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 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
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
Regards
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
DateTime.ParseExact(dateStr, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")
Cheers!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.