Need to save the date month year in asp.net using calendar
need to save the date month year in asp.net using calendar in sql server my date datatype is datetime
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj Kumar MandalPosted Apr 30, 2015, 5:55 AM
selvi subramanianPosted Apr 30, 2015, 5:24 AM
this is my code but date is inserrted like this...
my need is to save the dd/MM/yyyy only not the time
selvi subramanianPosted Apr 30, 2015, 3:50 AM
String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid DateTime.
Source Error: Line 1342: txsa.Text = Calendar5.SelectedDate.ToString(); Line 1343: Line 1344: string StartDate = DateTime.ParseExact(txsa.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("yyyy-MM-dd 00:00:01"); Line 1345: Line 1346:
Source File: d:\Modified\bramandam site\CommonExpenses.aspx.cs Line: 1344 Stack Trace: [FormatException: String was not recognized as a valid DateTime.] System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) +2846462 System.DateTime.ParseExact(String s, String format, IFormatProvider provider) +31 CommonExpenses.Calendar5_SelectionChanged(Object sender, EventArgs e) in d:\Modified\bramandam site\CommonExpenses.aspx.cs:1344 System.Web.UI.WebControls.Calendar.OnSelectionChanged() +123 System.Web.UI.WebControls.Calendar.SelectRange(DateTime dateFrom, DateTime dateTo) +295 System.Web.UI.WebControls.Calendar.RaisePostBackEvent(String eventArgument) +1012 System.Web.UI.WebControls.Calendar.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 Version Information: Microsoft .NET Framework Version:2.0.50727.3655; ASP.NET Version:2.0.50727.3658
Abhay ShankerPosted Apr 30, 2015, 3:31 AM
Manoj Kumar MandalPosted Apr 30, 2015, 2:23 AM
I'm expecting that you are selecting date in dd/MM/yyyy format.
Use below code to convert that string to a new string in yyyy-MM-dd hh:mm:ss format that can be saved to database.
Send this new date string in string type parameter to your procedure.
string StartDate = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("yyyy-MM-dd 00:00:01");