Subtracting a day from the date

I’m using this code here to subtract one day from the date in an automation.

DateTime.ParseExact(rentConfig(“Change”).ToString,“dd/mm/yyyy”,Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString(“dd/mm/yyyy”)

It works fine, unless the data input as rentConfig(“Change”) is the first of a month, in which case it changes the dd to the day before, but the mm doesn’t change. E.G 01/02/2018 input returns 31/02/2018 instead of 31/01/2018.

Can anyone suggest how to fix this? TIA

1 Like

One small thing that you used incorrectly.
dd/mm/yyyy as you know should be dd/MM/yyyy

Once you do that it will work. I have tested it.

1. d/D: day without 0 prefix on single digit. 
2. dd/DD: day with 0 prefix if single digit.
3. M: Month without 0 prefix on single digit.
4. MM: Month with 0 prefix if single digit.
5. yy/YY: Last two digit of year.
6. yyyy/YYYY: represents full year.
7. HH: 24 hour based hour. ie. 13:00. **H** will display hour without prefix 0 if single digit
8. hh: 12 hour based hour. ie. 01:00. **h** will display hour without prefix 0 if single digit
9. m: minute without 0 prefix on single digit. 
10.mm: minute with 0 prefix if single digit.
11.s: second without 0 prefix on single digit. 
12.ss: second with 0 prefix if single digit.
13.tt: represent the AM or PM
4 Likes

Thank you @nadim.warsi - that has worked! :slight_smile:

1 Like

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