Dorababu Meka

Dorababu Meka

  • 230
  • 8.3k
  • 1.7m

Why i am unable to convert Datetime to the requiredformat

Feb 19 2011 4:58 AM
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"


Answers (6)