Convert MM/DD/YYYY to DD/MM/YYYY

Is there an easy way of doing the following conversion:

MM/DD/YYYY to DD/MM/YYYY
M/D/YYYY to D/M/YYYY
MM/D/YYYY to D/MM/YYYY
M/DD/YYYY to DD/M/YYYY

The input that needs to be converted is a string and as shown above doesn’t contain the typical “0” if either month or day is less than “10”.

Use this @LarsFeilberg

DateTime.ParseExact(dt, “dd-MMM-yyyy”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“dd-mm-yyyy”)

Here dt is the input string and “dd-MMM-yyyy”, this is the input format you are providing to the method and “dd-mm-yyyy” is the output format you need :slight_smile:

2 Likes

I found that the following works:

Convert.ToDateTime(mystring).ToString(“dd/MM/yyyy”)

6 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.