Convert a string to DateTime

Hi ,

I have a string variable ‘ReconDate’ that accepts date from the user in the format ddMMyy (Eg:100319) .
I need to convert it to DateTime format so that I can use the AddDays() with it in order to get the previous date (090319) , so as to get the previous folders date(The folder names are in the format ddMMyy).

@itsahmedfiroz Check this Convert DateTime to string and remove unwanted time?

Hi @itsahmedfiroz,

You can try this also.

"strResult=New DateTime(Convert.ToInt32(strValue.Substring(4, 2)), Convert.ToInt32(strValue.Substring(2, 2)), Convert.ToInt32(strValue.Substring(0, 2))).AddDays(-1).ToString("ddMMyy") "

Sample :DateConversion.zip (2.1 KB)

Regards
Balamurugan.S

Convert.ToDateTime(ReconDate) - 1

Above should give you 090319 if ReconDate is 100319

Thanks :smiley: !

1 Like

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