How to get the date value of first day of previous month?

hi guys,
I am struggling to create a variable in UiPath studio that would look at the current date and define the first day of the previous month. Do you know if this is even possible? I am trying to avoid setting up this value in excel file and get UiPath to calculate this value itself.

Basically so far i have Date_Now variable which is simple “now” calculation in DateTime type.
2nd variable is Date_NowString which is Date_Now.ToString(“dd/MM/yyyy”) with a String type.

Is there any calculation how can i create Date_FirstOfPreviousMonth variable that would look at the above variables and give me the correct result?
e.g. if Date_NowString is 24/02/2020 i want Date_FirstOfPreviousMonth to return 01/01/2020 in either String or DateTime type.

Thank you!

Set Date_Now = Date_Now.AddMonths(-1), then Date_Now.Day = 1.

2 Likes

Hi,

Hope the following expression helps you.

Date_FirstOfPreviousMonth = new DateTime(Date_Now.Year,Date_Now.Month,1).AddMonths(-1)

Regards,

5 Likes

worked perfectly! thank you

1 Like

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