Converting date format to string

Hello everyone,
I have an excel which has column name date and it has value like Jan/15/2020 and it’s in date format but I want to convert it into string and when I am trying to convert in string it’s giving me error. Could you please help me I have. Tried parse method as well

Thanks please reply if you have anything I have attached the error screenshot

Error says, conversion is happening in opposite way.
You are trying to convert from String to Date.

If your date is in string format 11-Jan-2020 (as per your screenshot) - trying to convert to DateTime, follow as shown below.

strDate = "11-Jan-2020"
DateTime dateObj = DateTime.ParseExact(strDate,"dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture)

Regards,
Karthik Byggari

2 Likes

If the input date format in dd-MMM-yyyy
Result Assign in string variable → DateTime.ParseExact(your DateTime variable, “dd-MMM-yyyy”, System.Globalization.CultureInfo.InvariantCulture).Tostring(“MMM/dd/yyyy”)
If the input date format in MMM/dd/yyyy
Result Assign in string variable → DateTime.ParseExact(your DateTime variable, “MMM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).Tostring(“MMM/dd/yyyy”)