[Inquiry] Date formatting

Hello, all

I’m currently using below script. By the way, I wonder that if year is changed, what is the result of this script?

Current Code: now.addmonths(-1).tostring (“yyyy-MM”)
Example Today Date of Laptop : 2022-01-05
Expected Result of above code: 2021-12

If I run the code that I mentioned above, the result is same as that I expected …?
My PC date setting change is blocked due to internal policy, I cannot try test…
Thank you for your help!

the Code seems fine.

You can test like this also-

image

Now gives Date and all the methods of date will work fine on it.

1 Like

Thank you for helps! Confirmed it’s working fine.
image

Date.Parse(“2022-01-05”).AddMonths(-1).ToString(“yyyy-MM”)

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