sql - String to Datetime Conversion in Ajax CalendarExtender. -
in calender control : when select date, display in textbox in format : 15-06-2015 00:00:00 means "dd-mm-yyyy hh:mm:ss".
after converted textbox text datetime datatype using
datetime dt = convert.todatetime(txtdate.text);
and store database.
in database store in format : 2015-06-15 means "yyyy-mm-dd" because column datatype date.
in ajax calendarextender : using calendarextender ajexcontroltoolkit. don't use format attribute. default display in textbox in format : 6/16/2015 menas "mm/dd/yyyy"
try convert textbox string datetime datatype using same code
datetime dt = convert.todatetime(txtdate.text);
but error displayed "string not recognized valid datetime"
even try
datetime dt = datetime.parse(txtdate.text);
but same error displayed every time.
you have 2 options, provide format attribute ajax control or use datetime.parseexact
.
<ajaxtoolkit:calendar runat="server" targetcontrolid="date1" cssclass="classname" format="yyyy-mm-dd" popupbuttonid="image1" />
http://www.ajaxcontroltoolkit.com/calendar/calendar.aspx
using parseexact
:
datetime date = datetime.parseexact("6/16/2015", "m/dd/yyyy", null);
Comments
Post a Comment