日期时间格式 - 字符串不被识别为有效日期时间/'值'应在'MinDate'和'MaxDate'之间。 [英] Datetime Format - String is not recognized as a valid datetime / 'Value' should be between 'MinDate' and '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] [reg_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
我现在尝试了很多选项/可能性,但我还是无法将日期时间字段(到期)值提取到日期时间选择器。所以请在这方面帮助我。
尝试设置'12 / 14/2011'如果这样可以正常工作。那么你必须改变格式设置此日期之前的日期。
您的选择器采用此格式DD / MM / YYYY您必须将日期更改为此格式
< blockquote> hi。
将日期选择器格式化为MM / DD / YYYY格式。
你不会得到异常的taype
ExpiryDate.Value = Convert.ToDateTime(ds.Tables [ 0 ]。行[< span class =code-digit> 0 ] [ reg_expiry]。ToString ());
将DateTime
值转换为字符串的重点是什么?
为了将其转换回DateTime
?正如您所发现的那样,这是灾难的秘诀。在所有情况下都使用DateTime
值,除非您需要在某些用户可读设备上显示它。
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 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
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/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.
try to set '12/14/2011' If this will worked fine.Then you have to change the format of the date before setting this .
Your picker taking this format DD/MM/YYYY you have to change the date in to this format
hi.
chane you date picker formate into MM/DD/YYYY format.
you will not get that taype of exception
ExpiryDate.Value = Convert.ToDateTime(ds.Tables[0].Rows[0]["reg_expiry"].ToString());
What is the point of converting aDateTime
value to aString
in order to convert it back to aDateTime
? This is a recipe for disaster, as you have found. UseDateTime
values in all cases, except where you need to display it on some user readable device.
这篇关于日期时间格式 - 字符串不被识别为有效日期时间/'值'应在'MinDate'和'MaxDate'之间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!