Hi,
I am trying to read an excel range to a datatable and convert one of the Column value from String to DateTime type. My objective is to get the column format to match by SQL Server Table column datatype.
I tried-
Convert.ToDateTime(DateTime.ParseExact(row.Item(3).ToString,“dd-MM-yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).ToString(“YYYY-MM-DD hh:mm:ss.nnn”)
DateTime.ParseExact(row.Item(3).ToString,“dd-MM-yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
Convert.ToDateTime(row.item(3).ToString)
My Excel Cell value is in “dd-MM-yyyy hh:mm AM/PM” format and i want it to convert to “YYYY-MM-DD hh:mm:ss.nnn”
Yoichi
(Yoichi)
January 5, 2022, 7:32am
2
Hi,
If your data is stored as String in worksheet, can you try the following?
DateTime.ParseExact(row.Item(3).ToString,"dd-MM-yyyy hh:mm tt",System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss.fff")
or if your data is stored as datetime in worksheet, the following might work.
DateTime.Parse(row.Item(3).ToString).ToString("yyyy-MM-dd HH:mm:ss.fff")
Regards,
1 Like
Thankyou so much @Yoichi . I am able to convert the string to datetime format now. it was problem in format.
1 Like
system
(system)
Closed
January 8, 2022, 7:58am
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.