Hai i am getting a date input(Not the DateTime.Now) from the user and i want that to transform and show in a Date format. E.g: in the XAML, will be specified and i want that to be shown as "PrintedOn - October 24,2008" .The string formatting is string.format("{0} - {1}",userText, userDate). Where am i going wrong?How can i convert the UserDate to the formatting i need. Please pecify the code. Thanks
A:
if you have a date from the user:
If you need to get a date from a string, just use
DateTime. Parse(datestring)
jle
2009-11-01 15:12:00
But i am getting the input from the user as a string(XAML).So how can i convert it to Date?
Kaja
2009-11-01 15:17:37
A:
From your code sample, I assume this is C# or VB.NET.
String.Format("{0} - {1}", userText, userDate.ToString("D"))
does something along those lines, and gives you a string in the current locale as a bonus. See the possible format strings for more info.
Thomas
2009-11-01 15:13:57
+1
A:
Use this :
String.Format("{0} - {1}", userText, Date.Parse(userDate).ToString("MMMM dd,yyyy"))
where userDate is currently your date as an unspecified format in a string from the XAML. If you know the format it's arriving in, use ParseExact instead.
CodeByMoonlight
2009-11-01 15:27:22
this should probably be `String.Format("{0} - {1}", userText, (Convert.ToDateTime(userDate)).ToString("MMMM dd,yyyy"))` to correctly answer the question
Jim Schubert
2009-11-01 15:33:36
Hai,I think ur answer will work.But i am getting error.So i checked and i found that even the following code is not running.Any ideas?DateTime dateValue;string dateString = "2/16/2008 12:15:12 PM";dateValue = DateTime.Parse(dateString);when i debug, i cant pass the 3rd line..I am getting this error"String was not recognized as a valid DateTime"
Kaja
2009-11-01 16:23:55
Hai its working after adding this code Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");Thanks all..
Kaja
2009-11-01 16:49:24