[Solved] Convert yyyyMMdd date format to DateTime object in C# .Net

Last Reply on Dec 23, 2014 09:55 AM By Azim

Posted on Dec 22, 2014 09:44 PM


My scenario is I have on text box with date (dd-MM-yyyy). I am using ajax in this text box as you explain in Ajax date format link

I need this date display into another text box with format yyyyMMdd on click the button

Because the invoice Number needs the yyyyMMdd-00001 when the user select the date.

How can do this.


error is

System.FormatException: Input string was not in a correct format.

Pls advice me how to do it

Thank you


Posted on Dec 23, 2014 09:55 AM

Please refer this code


<cc1:ToolkitScriptManager runat="server">
<asp:TextBox ID="txtDate" runat="server" />
<cc1:CalendarExtender ID="ceDate" runat="server" TargetControlID="txtDate" Format="yyyyMMdd"

<asp:Button Text="Save Sate" OnClick="SaveDate" runat="server" />


using System.Globalization;


protected void SaveDate(object sender, EventArgs e)
    DateTime date = DateTime.ParseExact(this.txtDate.Text.Trim(), "yyyyMMdd", CultureInfo.InvariantCulture);