Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using text box as calender (and that text box text mode is calender ).
i want to save that text box date time into my db table (data type of column datetime) but this thing not working


C#
objClass.StartDateTime= Convert.ToDateTime(txtcalender.Text);


here it is showing me error
cannot convert string to date
if i ommit convert.todatetime then then it is show me cannot implicitly convert string to date.
what to do how can i access datetime from txtbox.
Posted

Use this code

DateTime dateValue;
CultureInfo culture = CultureInfo.CurrentCulture;
DateTimeStyles styles = DateTimeStyles.None;
DateTime.TryParse(datetimestring,culture, styles, out dateValue);
 
Share this answer
 
Comments
Muhamad Faizan Khan 27-Feb-14 0:21am    
what the heck is this
[no name] 27-Feb-14 0:31am    
DateTime dateValue;
CultureInfo culture = CultureInfo.CurrentCulture;
DateTimeStyles styles = DateTimeStyles.None;
DateTime.TryParse("19/12/1990", culture,styles, out dateValue);
lblOP.Text = dateValue + "";


I think now you will get this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900