本文介绍了日期时间格式 - 字符串不被识别为有效日期时间/'值'应在'MinDate'和'MaxDate'之间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好。 先谢谢。 我面临着日期格式方面的严重问题。 当我将到期日期提供给expirydate datetime选择器时。 它通常显示两个错误。 1.如果我曾经在数据集中显示日期时间选择器中的expirydate.text数据 字符串不被识别为有效日期时间 2.如果我曾经在数据集中显示为日期时间选择器中的expirydate.value数据 {System.ArgumentOutOfRangeException:'14 / 12/2011 00:00:00'的值对'Value'无效。 'Value'应该在'MinDate'和'MaxDate'之间。 参数名称:值 在System.Windows.Forms.DateTimePicker.set_Value(DateTime value) 在NWAFH_HIS.frmPatientRegistration.MainSearchResult()} 我的代码是这样的: // ExpiryDate.Value = Convert.ToDateTime(ds.Tables [0] .Rows [0] [reg_expiry]。ToString(),dateFormat); // ExpiryDate.Text = ds.Tables [0] .Rows [0] [r​​eg_expiry] ToString(); // DateTime dtime = Convert.ToDateTime(ds.Tables [0] .Rows [0] [reg_expiry]); string text = ds.Tables [ 0 ]。行[ 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 ]。行[ 0 ] [ 。reg_expiry]的ToString()); // ExpiryDate.Text = ds.Tables [0] .Rows [0] [reg_expiry] .ToString(); 我的数据库字段是'reg_expiry',我使用datetime作为格式。 所有数据保存为'2016-03-12 00:00:00.000',就像这种格式 我只是检索与日期时间相同的数据 我也试过 convert ( varchar ( 10 ),reg_expiry, 103 )和 convert ( varchar ( 10 ),reg_expiry, 101 ) 和Currenlty我的日期时间选择器属性是: 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 ; Maxdate:12/31 / 9998 和注意:1/1/1753 我现在尝试了很多选项/可能性,但我还是无法将日期时间字段(到期)值提取到日期时间选择器。所以请在这方面帮助我。解决方案 hi。 将日期选择器格式化为MM / DD / YYYY格式。 你不会得到异常的taype Hello. 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 datasetString is not recognized as a valid datetime2. 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 formatI am just retrieving the same data as a datetimeAlso i tried with convert(varchar(10),reg_expiry,103) and convert(varchar(10),reg_expiry,101)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/1753I 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. 解决方案 这篇关于日期时间格式 - 字符串不被识别为有效日期时间/'值'应在'MinDate'和'MaxDate'之间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 18:41