I have the following date stored as a string
04.09.2009 (dd.mm.yyyy)
Now I would like it changed to this format:
2009/08/31 (yyyy/mm/dd)
Remember output should be a string value and the input date is a string.
What is the best way to convert it with minimal effort?
Why are you storing the date as a string? That's generally a bad idea...
To convert the string you parse it into a DateTime value, the format that into a string:
string newFormat = DateTime.ParseExact(theDate, "dd'.'MM'.'yyyy", CultureInfo.InvariantCulture).ToString("yyyy'/'MM'/'dd")
(Note that you need apostrophes around the slashes to get the literal character, otherwise it will use the date separator character of the culture, which may be a different character.)
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