5 months start and end date

Guys, I have a query.

I want 5 months start and end date.
For eg. Start date - 01/03/2024 End date 31/03/2024.

I used below code but start date is wrong appears
Today.AddMonths(-5).AddDays(-cint(DateTime.now.ToString(“dd”))-1)

Can someone suggest

@Jeeru_venkat_Rao

First Date of the 5th previous month

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

Last Date of the previous 5th month

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

image

Thanks,
Ashok :slight_smile:

Hi @Jeeru_venkat_Rao

Can you try the below

Regards,

Hi @Jeeru_venkat_Rao

Check the below syntax:

Assign Activity -> startDate = New DateTime(DateTime.Now.AddMonths(-5).Year, DateTime.Now.AddMonths(-5).Month, 1).ToString("dd/MM/yyyy")

Assign Activity -> endDate = New DateTime(DateTime.Now.AddMonths(-4).Year, DateTime.Now.AddMonths(-4).Month, 1).AddDays(-1).ToString("dd/MM/yyyy")

Message Box -> "Start Date: " + startDate +Environment.NewLine + "End Date: " + endDate

Hope it helps!!

Thanks @ashokkarale
Its working fine

1 Like

Thank you @Parvathy @lrtetala @ashokkarale
You guys are awesome.

1 Like

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