We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how do i assign a datetime value to datetimepicker control

hi all, I want to assign a date to a datetimepicker control, I tried the following lines of code dtpPoDate = new DateTimePicker( ); dtpPoDate.Size = new Size( 100, 20 ); dtpPoDate.Location = new Point( 600, 80 ); dtpPoDate.CustomFormat = "dd'/'MM'/'yy"; dtpPoDate.Format = DateTimePickerFormat.Custom; Controls.Add( dtpPoDate ); dtpPoDate.Value = Convert.ToDateTime("01/01/02"); but I'm getting the error message as System.FormatException: Could not determine the order of year, month, and date from m/d/yyyy. at System.DateTimeParse.GetYearMonthDayOrder(String datePattern, DateTimeFormatInfo dtfi) at System.DateTimeParse.GetDayOfNNN(DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider) at System.DateTime.Parse(String s) at System.Convert.ToDateTime(String value) at testdatagrid.GetPoDet() at testdatagrid.OnGotFocus_cmbSuppId(Object Sender, EventArgs e) at System.Windows.Forms.Control.OnGotFocus(EventArgs e) at System.Windows.Forms.Control.WmSetFocus(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ComboBox.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) could some one help me how to get this out ? regards, lat.

2 Replies

DL danny liao October 29, 2002 02:32 PM

Hi,lat You're using the wrong format. This should work: change: dtpPoDate.CustomFormat = "dd'/'MM'/'yy"; to: dtpPoDate.CustomFormat = "dd/MM/yy"; and dtpPoDate.Value = Convert.ToDateTime("01/01/02"); to: dtpPoDate.Value = Convert.ToDateTime("01/01/2002") > hi all, > > I want to assign a date to a datetimepicker control, > I tried the following lines of code > > dtpPoDate = new DateTimePicker( ); > dtpPoDate.Size = new Size( 100, 20 ); > dtpPoDate.Location = new Point( 600, 80 ); > dtpPoDate.CustomFormat = "dd'/'MM'/'yy"; > dtpPoDate.Format = DateTimePickerFormat.Custom; > Controls.Add( dtpPoDate ); > > dtpPoDate.Value = Convert.ToDateTime("01/01/02"); > > > > but I'm getting the error message as > > System.FormatException: Could not determine the order of year, month, and date from m/d/yyyy. > at System.DateTimeParse.GetYearMonthDayOrder(String datePattern, DateTimeFormatInfo dtfi) > at System.DateTimeParse.GetDayOfNNN(DateTimeResult result, DateTimeRawInfo raw, > > DateTimeFormatInfo dtfi) > at System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, > > DateTimeRawInfo raw, DateTimeFormatInfo dtfi) > at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) > at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles) > at System.DateTime.Parse(String s, IFormatProvider provider) > at System.DateTime.Parse(String s) > at System.Convert.ToDateTime(String value) > at testdatagrid.GetPoDet() > at testdatagrid.OnGotFocus_cmbSuppId(Object Sender, EventArgs e) > at System.Windows.Forms.Control.OnGotFocus(EventArgs e) > at System.Windows.Forms.Control.WmSetFocus(Message& m) > at System.Windows.Forms.Control.WndProc(Message& m) > at System.Windows.Forms.ComboBox.WndProc(Message& m) > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr > > lparam) > > > could some one help me how to get this out ? > > regards, > lat. > >


AD Administrator Syncfusion Team July 8, 2003 09:29 AM

> hi all, > > I want to assign a date to a datetimepicker control, > I tried the following lines of code > > dtpPoDate = new DateTimePicker( ); > dtpPoDate.Size = new Size( 100, 20 ); > dtpPoDate.Location = new Point( 600, 80 ); > dtpPoDate.CustomFormat = "dd'/'MM'/'yy"; > dtpPoDate.Format = DateTimePickerFormat.Custom; > Controls.Add( dtpPoDate ); > > dtpPoDate.Value = Convert.ToDateTime("01/01/02"); > > > > but I'm getting the error message as > > System.FormatException: Could not determine the order of year, month, and date from m/d/yyyy. > at System.DateTimeParse.GetYearMonthDayOrder(String datePattern, DateTimeFormatInfo dtfi) > at System.DateTimeParse.GetDayOfNNN(DateTimeResult result, DateTimeRawInfo raw, > > DateTimeFormatInfo dtfi) > at System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, > > DateTimeRawInfo raw, DateTimeFormatInfo dtfi) > at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) > at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles) > at System.DateTime.Parse(String s, IFormatProvider provider) > at System.DateTime.Parse(String s) > at System.Convert.ToDateTime(String value) > at testdatagrid.GetPoDet() > at testdatagrid.OnGotFocus_cmbSuppId(Object Sender, EventArgs e) > at System.Windows.Forms.Control.OnGotFocus(EventArgs e) > at System.Windows.Forms.Control.WmSetFocus(Message& m) > at System.Windows.Forms.Control.WndProc(Message& m) > at System.Windows.Forms.ComboBox.WndProc(Message& m) > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr > > lparam) > > > could some one help me how to get this out ? > > regards, > lat. > >

Loader.
Live Chat Icon For mobile
Up arrow icon