Date time conversion to string and get only date in string format

I am reading the value from excel, the data in the excel is in DateTime format

MM/dd/yyyy HH:mm:ss but i want it to be in MM/dd/yyyy in string format.

Hi @hansen_Lobo

DateTime.ParseExact(Input.ToString,"MM/dd/yyyy hh:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

Check this below code,
DateTime.ParseExact("10/29/2023 00:00:00","MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")


CDate("10/29/2023 00:00:00").ToString("MM/dd/yyyy")

Hope this may help you :slight_smile:

1 Like

What if i want to convert MM/dd/yyyy hh:mm:ss from string format to datetime format?

Then you can use below code,
DateVar(DateTime type) = DateTime.ParseExact("10/29/2023 00:00:00","MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture)

1 Like

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