hello all aim a newbie in c# please tell me
how shall i convert string 5/15/2008 to date time 15/5/2008 in c#
and copmare the same with 14/5/2008
Usually dates are changed around based on the user's Culture.
If your culture is set to en-US then your dates will be displayed:
"mm/dd/yyyy"
Whereas if your culture is set to fr-FR or es-ES then your dates will be displayed:
"dd/mm/yyyy"
By setting your user's culture you can format the way things are displayed...
- Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
Please note that the above code will not only display your dates in the format for en-US, it will also attempt to look for any resources indicated for en-US.
If you want to force your date to always be in one format, despite the user's culture settings, use the
DateTimeFormatInfo object...
You should also look into Globalization.
-Frinny