How to parse exact date?

how to parse exact date from 05/01/2020 to 5/01/2020?

give a try on DateTime.ParseExact(“05/01/2020”,“dd/MM/yyyy”, CultureInfo.InvariantCulture).toString(“d/MM/yyyy”)

it is assumed that 05 is the day otherwise flip it in the format string
Ensure System.Globalization is imported


05 is the month… thanks for the answer but i’m getting this kind of error…

you got this error because of your fromdate variable is of datatype DateTime
But the statement is returning a string:

you can resolve it by following:
DateTime.ParseExact(“05/01/2020”,“dd/MM/yyyy”, CultureInfo.InvariantCulture)
parse the string into a datetime

Once you do need this other format (e.g. DataEntry) then use fromdate.toString(“d/MM/yyyy”)

DateTime will have its internal format and this is to keep as it is


thank you so much! it helped me a lot!

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