Get the previous month and year

hello all;

I used DateTime.Now.AddMonths(-1).toString

And for year :Sytem.DateTime.Now.year.ToString

but problem when we are in january 2023 , the previous month is 12
then the year must be 2022

How we resolve this
Best Regards

Hi @nora_ziani

Try with this expression

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

image

Regards
Gokul

HI @nora_ziani

Checkout this expression

Now.AddMonths(-1).Year.ToString

Regards
Sudharsan

IT IS NOT what i want

we must add a condition in order to know if we are in decembre (year _1)
and for the other months we use actual year

Then you need to explain little bit more @nora_ziani

the expression will give you the year like

if current month is jan you will get previous year if currentmonth is feb you will get current year @nora_ziani

Hello @nora_ziani
May be you are looking for this
image

Hi,
Use modify date activity.
image

YES THAT is the need
best regards

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