I need to get previous month from today's date

I need to get previous month from today’s date

For example

Today’s date:12/15/2022

My output should be:11/15/2022

Another example:

Consisder Today’s date:01/15/2022

My output should be:12/15/2021

Hi @sruthesanju

Now.addmonths(-1)

Cheers

1 Like

Hi @sruthesanju
Please try this function to get the date.

get today’s date

today = DateTime.Now

get the previous month from today’s date

prevMonth = today.AddMonths(-1)

HI @sruthesanju

Another Method is like you can pass your input string into the expression like in the image

DateTime.ParseExact("01/15/2022","MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture).AddMonths(-1).ToString("MM/dd/yyyy")

image

Here Now.addmonths(-1) will give the only the previous month date not your required output

image

Regards
Gokul

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