Get last date of previous month

how to get last date of previous month on date modify activity e.g 30/11/2023 ???

Hi @Hemant_Deshmukh

Try this:

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

You can change the date format as required. As per your requirement

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

str_lastdate is of DataType System.String

Hope it helps!

Hi @Hemant_Deshmukh

Assign activity:
DateTime lastDayOfPreviousMonth =DateTime.Now.AddDays(-DateTime.Now.Day)
Message box
lastDayOfPreviousMonth.ToString("dd/MM/yyyy")

@Hemant_Deshmukh
Cheers

@Hemant_Deshmukh

try this :

DateTime.Now.AddMonths(-1).AddDays(-DateTime.Now.Day)

cheers…!

Hi @Hemant_Deshmukh

How about the following?

Cheers!!

Hi,

you can use modify activity as below ss

image

Modify_Date.zip (2.7 KB)

Hello @Hemant_Deshmukh

You can try to do this :
1 . Declare a variable
2 . Assign its value as n
new DateTime(now.Year , now.Month , 1).AddDays(-1).ToString(“dd/MM/yyyy”)
It will give you expected results.

Hi @Hemant_Deshmukh

How about this

lastDayOfPreviousMonth (DateTime)= New DateTime(Now.Year, Now.Month, 1).AddDays(-1)

formattedDate (String) = lastDayOfPreviousMonth.ToString(“dd/MM/yyyy”)

Hi @Hemant_Deshmukh

Try this:

DateTime.Now.AddMonths(-1).AddDays(-DateTime.Now.Day).ToShortDateString

For change Date Format as per your requirement.

DateTime.Now.AddMonths(-1).AddDays(-DateTime.Now.Day).ToString(“dd-MM-yy”)

Hope it will helps you :slight_smile:
Cheers!!

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