2
Answers

Date time convertion error

I am using Data base date formate is  31/12/2032 
 

DateTime MembershipValidity = Convert.ToDateTime(dt.Rows[0]["MembershipValidity"]);
 using this coding 
 i got date time convertion error please clarify this
 
 

Answers (2)

1
Photo of Nitin Sontakke
137 13.6k 15.4k 8y
First thing to note that there is no such thing as "database date format".
 
Are you using SQL Server? What is the datatype of MembershipValidity? Is it DateTime or VarChar?
 
What is the datetime format in regional settings of your computer? This all matters.
 
0
Photo of Sujeet Suman
378 4.1k 1.6m 8y
Please once try below code:-
 
try
   string db_Date = dt.Rows[0]["MembershipValidity"].ToString();
   DateTime MembershipValidity = Convert.ToDateTime(db_Date );
}
catch(Exception) 
{
   throw;