Change date format changes

hi team ,
some times i m getting date as 1/2/2024 in (mm/dd/yyyy) format … and sometime i will get as (01/02/2024) …
if i get 1/2/2024 … like this … i want 01/02/2024

can u please suggest something on this

Hi @Nikhil_Katta

Try this

Input = "1/2/2024"
Output= DateTime.ParseExact(Input,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyy")

Works whether format is 1/2/2024 or 01/02/2024 also


DateTime.ParseExact("1/2/2024", {"M/d/yyyy", "MM/dd/yyyy"}, System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

It will work for you in both cases

1 Like

Hi @Nikhil_Katta

DateTime.ParseExact(dateStr, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")


1 Like

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