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.
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
Manoj Kumar Mandal198 reputationPosted Apr 29, 2015, 10:23 PM EDT
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");
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 29, 2015, 11:31 PM EDT
selvi subramanianRank #2,007 · 723 reputationPosted Apr 29, 2015, 11:50 PM EDT
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
selvi subramanianRank #2,007 · 723 reputationPosted Apr 30, 2015, 1:24 AM EDT
this is my code but date is inserrted like this...
my need is to save the dd/MM/yyyy only not the time
Manoj Kumar Mandal198 reputationPosted Apr 30, 2015, 1:55 AM EDT