Click here to Skip to main content
12,896,953 members (51,935 online)

Datetime Format - String is not recognized as a valid datetime / 'Value' should be between 'MinDate' and 'MaxDate'.

fazal2010 asked:

Open original thread

Thanks in Advance.

I am facing serious problem regarding date format.
When i am fetching my expiry date to the expirydate datetime picker.
It showing the two errors commonly.

1. If i used to show as expirydate.text data in date time picker from dataset
String is not recognized as a valid datetime
2. If i used to show as a expirydate.value data in date time picker from dataset
{System.ArgumentOutOfRangeException: Value of '14/12/2011 00:00:00' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.
Parameter name: Value
at System.Windows.Forms.DateTimePicker.set_Value(DateTime value)
at NWAFH_HIS.frmPatientRegistration.MainSearchResult()}

MY Code is like this way :
//ExpiryDate.Value = Convert.ToDateTime(ds.Tables[0].Rows[0]["reg_expiry"].ToString(), dateFormat);
                  //ExpiryDate.Text = ds.Tables[0].Rows[0]["reg_expiry"]ToString();
                  //DateTime dtime = Convert.ToDateTime(ds.Tables[0].Rows[0]["reg_expiry"]);
                  string text = ds.Tables[0].Rows[0]["reg_expiry"].ToString();
                  DateTime ddate = DateTime.Parse(text, dateFormat);
                  //string text = dtime.ToString("dd/MM/yyyy", dateFormat);
                  ////ExpiryDate.Value = Convert.ToDateTime(DateTime.Parse(String.Format("{0:MM/dd/yyyy}", ddate).Trim()));
                  //ExpiryDate.Text = String.Format("{0:MM/dd/yyyy}", ddate).Trim();
                  //ExpiryDate.Text = text;
                  //ExpiryDate.Text = (ds.Tables[0].Rows[0]["reg_expiry"]).ToString("dd/MM/yyyy");
  ExpiryDate.Value = Convert.ToDateTime(ds.Tables[0].Rows[0]["reg_expiry"].ToString());
                     //ExpiryDate.Text =  ds.Tables[0].Rows[0]["reg_expiry"].ToString();

My Database field is 'reg_expiry' and i used datetime as the format.
And all the data saved as '2016-03-12 00:00:00.000' like this format
I am just retrieving the same data as a datetime
Also i tried with

And Currenlty my datetime picker property is :
this.ExpiryDate.CustomFormat = "dd/MM/yyyy";
         this.ExpiryDate.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.ExpiryDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
         this.ExpiryDate.Location = new System.Drawing.Point(7, 125);
         this.ExpiryDate.Name = "ExpiryDate";
         this.ExpiryDate.Size = new System.Drawing.Size(120, 22);
         this.ExpiryDate.TabIndex = 50;

with Maxdate : 12/31/9998 and Mindate : 1/1/1753

I tried lots of options/ possibilities unitl now , But still i cannot fetch the datetime field(expiry) value to the datetime picker. So please help me in this regard.
Tags: C#, SQL-Server (SQL-server-2005), DateTime


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100