"dd MM yyyy" to dd/MM/yyyy

I’ve got an issue:
I have a string = “28 01 2019”
I want to convert to Date but it’s giving me System Format Exception because it’s taking 28 as a month not as a day.

I knew the issue because I was taking several dates = 01… 02… 03… and when comes 13 gives me the exception

How can I let him know that the first numbers are not month?


1 Like

@KevinDS datetime.parseexact(datestring variable,“dd MM yyyy”,system.globalization.cultureinfo.invariantculture).tostring("dd/MM/yyyy) try like this.

1 Like

Fine in that case we can mention the date first and month next
Like this
String = DateTime.ParseExact(stringvariable,”dd MM yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd MM yyyy”)

Now the output would be like dd MM yyyy so the machine won’t get us any exception
The reason each instance might take its date input in different format and we need to mention that based on how it takes

Hope this would help you
Cheers @KevinDS