Time and datetime format with Informix and .NET
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.
精彩评论