What is the most effective way to handle date strings which expected format is dd/MM/yyyy but come as d/M/yyyy

Hello guys,
I am asking this question so i can avoid writing long if-else statements in my code.
I have a date string and the format is supposed to be dd/MM/yyyy, unfornately on days like 5th of may 2022, the date string appears as 5/5/2022. I am trying to avoid if-else statements i simply want to make this 5/5/2022 appear as 05/05/2022 so it can be validated perfectly using DateTime.TryParseExact.
Please how do i do this ?

I am trying to avoid this here because it can get really wild :smiling_face_with_tear:


Just use "d/M/yyyy". It can handle both 05/05/2022 and 5/5/2022.


wowu! why didn’t i think of this … :smile: thank you so much , works @ptrobot

1 Like

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