Can i convert string to Date date type...?
Is ther any syntex/command to convert string variable to date variable...
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 attend5days leftRegister
SrinivasRank #3,567 · 408 reputationPosted May 18, 2009, 11:10 PM EDT
This way u can change the data formate and convert to string into data
string UrDate = txtPurchase_Dt.Text;
System.Globalization.DateTimeFormatInfo dateInfo = new System.Globalization.DateTimeFormatInfo();
dateInfo.ShortDatePattern = "dd/MM/yyyy";
DateTime validDate = Convert.ToDateTime(UrDate, dateInfo);
This way you can compate the dates in your application.
DateTime dt1 = new DateTime(2007, 11, 15);
DateTime dt2 = new DateTime(2008, 11, 15);
if (DateTime.Compare(dt1, dt2) < 0)
{
}
else if (DateTime.Compare(dt1, dt2)> 0)
{
}
Please try this solution. I think it will work.
Tejaswini Prashant J78 reputationPosted May 18, 2009, 8:54 PM EDT
string strdate = "11/30/2003" ;
DateTime dt = DateTime.Parse(strdate);
or u can also use
DateTime dt = Convert.ToDateTime(strdate);
2nd way
(this works for the given 3 strings dates)
// string strDate="2002-10-03";
// string strDate="10/04/2002";
string strDate="10/05";
DateTime dt = (DateTime)(System.ComponentModel.TypeDescriptor.GetConverter(new DateTime(1990,5,6)).ConvertFrom(strDate));
Hope this will help u out :)
Dnt forget to mark as an answer , if it is :)
Harish kharvi24 reputationPosted May 18, 2009, 9:13 PM EDT
Thank you Sir for your support....
I hope this answer will work....
Harish kharvi24 reputationPosted May 18, 2009, 9:16 PM EDT
Harish kharvi24 reputationPosted May 18, 2009, 11:25 PM EDT