Conversion string to date type?
How can we convert a string value into data type "Date"?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 1, 2012, 6:52 AM EST
You can convert a string to a DateTime using one of these methods:
Convert.ToDateTime
DateTime.Parse
DateTime.TryParse
Here are the links to the MSDN docs for these methods:
http://msdn.microsoft.com/en-us/library/xhz1w05e.aspx
http://msdn.microsoft.com/en-us/library/1k1skd40.aspx
http://msdn.microsoft.com/en-us/library/system.datetime.tryparse.aspx
Satyapriya NayakRank #47 · 31.5K reputationPosted Feb 1, 2012, 7:04 AM EST
private void Form1_Load(object sender, EventArgs e)
{
string strDate = "2002-10-03";
DateTime dtDate = Convert.ToDateTime(strDate);
or
DateTime dtDate = DateTime.Parse(strDate);
MessageBox.Show(dtDate.ToString());
}
Thanks
khaleel shaik11 reputationPosted Feb 12, 2012, 11:50 PM EST
DateTime dt=convert.ToDateTime(varaible Name);