Datetime period

Hello everyone, I need two datetime variables:

Current date minus 3 months and then the first day of the month

Current date minus 1 month and the last day of the month How does this work?

Many thanks in advance.

hi @Prisemuetchen

Hope this helps.

Now.AddMonths(-3).AddDays(-Now.Day+1)

Now.AddDays(-Now.Day)

You can use AddMonths function, AddDays Function and pass numeric values to get what you want.
Now.Day will give the day of month.

Thanks

Happy Automation!

DateAdd(DateInterval.Month,-3,Now)

The first day of a month is always 1 so…

New DateTime(DateAdd(DateInterval.Month,-3,Now).Year,DateAdd(DateInterval.Month,-3,Now).Month,1)

DateAdd(DateInterval.Month,-1,Now)

And then use DaysInMonth…

New DateTime(DateAdd(DateInterval.Month,-1,Now).Year,DateAdd(DateInterval.Month,-1,Now).Month,System.DateTime.DaysInMonth(DateAdd(DateInterval.Month,-1,Now).Year,DateAdd(DateInterval.Month,-1,Now).Month))

image

Hi @Prisemuetchen

For the first scenario, use the below one to get the minus 3 months and get the first date of that month,

FirstDayOfMonth = New DateTime(Now.AddMonths(-3).Year, Now.AddMonths(-3).Month, 1)

For the second scenario, use the below expression to get the minus 1 month and get the last date of that month,

LastDayOfMonth = New DateTime(Now.AddMonths(-1).Year, Now.AddMonths(-1).Month, DateTime.DaysInMonth(Now.AddMonths(-1).Year, Now.AddMonths(-1).Month))

Hope it helps!!

Hey @Prisemuetchen
You can use this flow:

  1. Assign date3MonthsAgo = Now.AddMonths(-3)
  2. Assign firstDayMinus3Months = new DateTime(date3MonthsAgo.Year, date3MonthsAgo.Month, 1)
  3. Assign date1MonthAgo = Now.AddMonths(-1)
  4. Assign lastDayMinus1Month = new DateTime(date1MonthAgo.Year, date1MonthAgo.Month, DateTime.DaysInMonth(date1MonthAgo.Year, date1MonthAgo.Month))

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.