I am sending in a string in dd/MM/yyyy
format, which is then being parsed into lv-LV
culture as set per the web.config globalization setting.
I am then comparing the date to DateTime.Now
to see if it is in the past.
The problem is, DateTime.Parse
converts my string to dd.MM.yyyy
format, but DateTime.Now has MM.dd.yyyy
format, so the comparison always fails.
Why would DateTime.Now
be different to the output from DateTime.Parse
, on the same thread culture?
Thanks!
(Update) This is the code I am using:
InputText contains input from a form in DD.MM.YYYY format
DateTime date = DateTime.Parse(InputText, CultureInfo.CurrentCulture);
// Check it's not in the past
this.IsValid = (date.CompareTo(DateTime.Now) > 0);
[DateTime.Now] in this context is in MM.DD.YYYY format using lv-LV cultureInfo [date] is in DD.MM.YYYY format after the DateTime.Parse