I am having my object variable declared as DateTime.
My date string is as follows
string strDate = "9999-12-31 00:00:00";
I use the below conversion
string FormatDateString(string strDate)
{
DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-ddTHH:mm:ss", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
return dt.ToString("yyy-MM-dd");
}
But while assigning to my object which was declared as DateTime i am getting an error if i convert it to datetime and assign i am missing the format i required so can any one tell how can i pass the one i needed to my object
I would like to pass Date to the object as "yyyy-MM-dd"
Loading


Madhu KRank #1,514 · 1.1K reputationPosted Feb 19, 2011, 12:56 AM EST
DateTime dt5 = DateTime.ParseExact(strDate, "yyyy-MM-dd HH:mm tt", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
Dorababu MekaRank #457 · 5.5K reputationPosted Feb 19, 2011, 12:58 AM EST
Madhu KRank #1,514 · 1.1K reputationPosted Feb 19, 2011, 1:04 AM EST
Yes you will get the error because 9999-12-31 21:34 PM format is not same as yyyy-MM-ddTHH:mm tt so change the format to yyyy-MM-dd HH:mm tt in following statement DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-ddTHH:mm:ss", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);Dorababu MekaRank #457 · 5.5K reputationPosted Feb 19, 2011, 1:12 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 19, 2011, 1:18 AM EST
Madhu KRank #1,514 · 1.1K reputationPosted Feb 19, 2011, 1:24 AM EST
DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
return dt.ToString("yyy-MM-dd");