In my c# program, a user can pick a date from a winforms date-time-picker. This is named
Here is my code:
DateTime selectedDate = dtpOutbox.Value.Date; TimeSpan ts = new TimeSpan(23,59,59); DateTime endOfSelectedDay = selectedDate + ts; Console.WriteLine(selectedDate.ToString("yyyy-MM-dd hh:mm:ss")); Console.WriteLine(endOfSelectedDay.ToString("yyyy-MM-dd hh:mm:ss"));
Now if todays date is 22nd Feb, it is my understanding that this should output (desired output):
2013-02-22 00:00:00 2013-02-22 23:59:59
But this is not the case. My output is:
2013-02-22 12:00:00 2013-02-22 11:59:59
I'm pretty sure this is a formatting issue, as when I display the DateTime values without a format string (selectedDate.ToString()) then it displays 22/02/2013 00:00:00 correctly. However I need my dates in the format of 22-02-2013 00:00:00.
Any ideas why C# is deciding that my first date is going to be midday, and my second date is going to be 11:59:59?