Conversion of a object into a particular datetime format
-
Dear Friends, I want to convert a query string object into a datetime in this format:- "YYYY-mm-dd HH:mm:ss.xxx" in C#.net. But when i am using Convert.ToDateTime(object) for getting the datetime value then an exception is being fired. Could anyone can provide me the iFormatProvider for the same.? Thanks Varun Sareen
-
Dear Friends, I want to convert a query string object into a datetime in this format:- "YYYY-mm-dd HH:mm:ss.xxx" in C#.net. But when i am using Convert.ToDateTime(object) for getting the datetime value then an exception is being fired. Could anyone can provide me the iFormatProvider for the same.? Thanks Varun Sareen
Try using DateTime.ParseExact instead MSDN[^]
string dateString, format;
...
DateTime result;
CultureInfo provider = CultureInfo.InvariantCulture;
result = DateTime.ParseExact(dateString, format, provider);You can build your format from the format specifiers: Formatting a DateTime for display format string[^] - they work the other way as well.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.