Get yesterdays date when at a new month

Every day, my process needs to get yesterdays date, which I have solved with:
DateTime.Now.AddDays(-1).ToString(“ddMMyy”)

This works fine.

I am wondering though, when I get to next month (first of March, 010319) I need to get the last of February (280219).

Will the code above fix that by itself or will it say that the day is 0 when I reach the first of each month?

Thanks

Regards
Johan

Hi @johan.standeus,

It will work fine even at the beginning of a new month. What it does is, by specifying -1 it will automatically get the previous date of the current irrespective of whether its a new month or a new year

Thanks
Lahiru

1 Like

Great, thanks for the quick reply!

Regards
Johan

1 Like

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