Probably a simple question -
I'm reading in data from a number of files.
My problem is, that when I'm reading in the date from an american file, I parse it like so:
DateSold = DateTime.Parse(t.Date)
This parses the string t.Date into a date format, however it formats the american date to a european date, e.g.
If the date is in the file as 03/01/2011, it is read as the 3rd of January, 2011, when it should be the 1st of March 2011.
Is there a way of doing this so that it formats to the european date?
var dt = DateTime.ParseExact(t.Date, "MM/dd/yyyy", CultureInfo.InvariantCulture);
The DateTime itself has no formatting, it is only when you convert it to or from a string that the format is relevant.
To view your date with American format, you pass the format to the ToString method
string americanFormat = dt.ToString("MM/dd/yyyy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With