How to get the first date and last date of the previous month using today's date?

Hi All,

I am trying to fetch the first day and last day for previous month using today’s date. For example if today’s date i.e(24-01-2023) then my output should be 01-12-2022 and 31-12-2022 respectively , for Feb I should get 01-02-2023 and 28-02-2023 and that should work for leap year as well.?

Thanks,
Vijay

HI @Vijaya_Kannan_Mani

How about this expression

First Date of the previous month

New DateTime(Now.Year,Now.Month,1).AddMonths(-1).ToString(“dd/MM/yyyy”)

Last Date of the previous month

New DateTime(Now.Year,Now.Month,1).AddDays(-1).ToString("dd/MM/yyyy")

image

Regards
Gokul

Thanks Gokul for your reply. I guess that works for Leap year as well!!

Yes @Vijaya_Kannan_Mani

Kindly close this topic by mark as solved.

Regards
Gokul