Reputation:
I have a text box that is set to todays date. The problem is its formatted on the form for visual ref as 07/12/12 but it needs to be on the report(word doc/data thru mail merge) as July 12, 2012. the user can edit the date, it just populates with todays date as that is used the most.
string today = DateTime.Now.ToString("MMddyy");
LetterDate.Text = today;
var Date = String.Format(DateTime.ParseExact(LetterDate.Text,"MMddyy", CultureInfo.CurrentCulture).ToString(), "MMMM dd, yyyy");
Date gives the output as 7/12/2012 12:00:00 AM --- im so lost at to why/how its even getting that format.
I know this should be easy, but its end of day and im just not seeing it.
Upvotes: 0
Views: 1589
Reputation: 6130
Try
string today = DateTime.Now.ToString("MMddyy");
LetterDate.Text = today;
var date = Convert.ToDateTime(LetterDate.Text).ToString("MMMM dd, yyyy");
take a look on this site for more reference:
Custom Date and Time Format Strings MSDN
String Format for DateTime C# Corner
Best Regards
Upvotes: 1
Reputation: 11191
you can achieve the format July 12, 2012 with out using DateTime.Parse like this:
LetterDate.Text.ToString("MMMM dd, yyyy");
Upvotes: 0