开发者

Time and datetime format with Informix and .NET

开发者 https://www.devze.com 2023-03-14 13:16 出处:网络
I have a table which has starttime fi开发者_如何学Goeld.this field of type DateTime and I configure it to (Hour to Minute) in Specials, because I wanna to store only time in this format.

I have a table which has starttime fi开发者_如何学Goeld.this field of type DateTime and I configure it to (Hour to Minute) in Specials, because I wanna to store only time in this format.

ex:10:45

Now in my code : I have the following problem:

 prd.StartTime = DateTime.Parse(record[1]);//.ToString("H:m"));


After Tracing: `StartTime = 6/22/2011 10:45:00 AM`

When I insert a record in this table, I get the following exception:

IBM.Data.Informix.IfxException: ERROR [22008] [Informix .NET provider][Informix]
Non-numeric character in datetime or interval.

EDIT: When I make default value enabled to this field and try to insert without starttime, and select the value I found it was 17:48, and when I change the Special to Year again the default value is 2011-06-22 17:48:00.


EDIT2:

I make StartTime property as string rather than DateTime, and succeed to insert. Does this affect the validity of this field later.


DateTime date = DateTime.Parse("10:45");

its working for me, I think you need to check what is the value stored in record[1]


I think this help you:

prd.StartTime = DateTime.Parse(record[1].ToString());


DateTime.Parse("10:45") is perfectly valid. However, it will produce an instance of DateTime containing today's date together with the time that you have parsed.

But the error you're getting is probably caused by the fact that the database you're using wants to store the date as a number.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号