String formatting date from yyyyMMdd to dd.MM.yyyy

I have a date in string format 20230525 I want to convert it to 25.05.2023 this new date should also be in string format.

Thanks

@ravig1206

Please try this

DateTime.ParseExact(stringdatevar,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture).ToString("dd.MM.yyyy")

Cheers

DateTime.ParseExact(dateST.ToString(),“yyyyMMdd”,Globalization.CultureInfo.InvariantCulture).ToString(“dd.MM.yyyy”) Then I converted with this; Convert.ToDateTime(formattedDate)

Hi,

FYI, another approach:

System.Text.RegularExpressions.Regex.Replace(yourString,"(\d{4})(\d{2})(\d{2})","$3.$2.$1")

Regards,

2 Likes

Hi @ravig1206

Try this-

string originalDate = “20230525”;
DateTime parsedDate = DateTime.ParseExact(originalDate, “yyyyMMdd”, null);
string formattedDate = parsedDate.ToString(“dd.MM.yyyy”);

Thanks!!

Thanks :slight_smile: It worked

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