+ 1

Get previous dates in sequence

I have date that I get from Date Time Picker for example string date1 = dateTimePicker1.Value.ToString("yyyy-MM-dd"); It gives me 2017-12-23 Now I need previous date to save in date2 variable string date2 = "code for this"; // it should be 2017-12-22 Please help.

23rd Dec 2017, 11:38 AM
Salman Mushtaq
Salman Mushtaq - avatar
2 Antworten
+ 4
You can use DateTime dt = new DateTime(year, month, day).AddDays(-1); And get day from it with specified format
23rd Dec 2017, 11:49 AM
Dima Makieiev
Dima Makieiev - avatar
+ 2
@DIma, thanks for solution.
23rd Dec 2017, 12:15 PM
Salman Mushtaq
Salman Mushtaq - avatar