Get previous dates in sequence | SoloLearn: Learn to code for FREE!

+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.

12/23/2017 11:38:20 AM

Salman Mushtaq

2 Answers

New Answer

+4

You can use DateTime dt = new DateTime(year, month, day).AddDays(-1); And get day from it with specified format

+2

@DIma, thanks for solution.