but that gives me a "string was not recognized as a valid datetime" error... But i'm sure that the value of the property is correct.. cause if i write out the value alone.. i get 2011-06-15T18:14:00.. which looks pretty valid to me..
great, this works, but when i dont choose a date in the datepicker the value i still get when reading the property is 0001-01-01T00:00:00, which i would think is the datetime.minvalue...
But when i try to compare the above value with the dateTime.MinValue its false.. Is there a best practice to check for 'empty' dates in umbraco using API...
problem parsing datepicker value to DateTime with API
hey guys,
i have a strange problem. I have a "date with time" picker in one of my document types.
When i select a date it shows as: 2011-06-15 18:14:00 in the field. No problem there..
Now from code i get the property of the node:
but that gives me a "string was not recognized as a valid datetime" error... But i'm sure that the value of the property is correct.. cause if i write out the value alone.. i get 2011-06-15T18:14:00.. which looks pretty valid to me..
I also tried :
DateTime.ParseExact(node.GetProperty("startDatetime").Value,"yyyy-MM-dd H:mm", null);
But that didnt help aswell..
I know i must miss something.. so if you guys can help me out... i would really appreciate it..
thanks alot..
The date time you get is in the so-called XML datetime format, DateTime can not parse that, you'll need to use this method instead:
System.Xml.XmlConvert.ToDateTime( "2011-06-15T18:14:00" )
regards, Steen
great, this works, but when i dont choose a date in the datepicker the value i still get when reading the property is 0001-01-01T00:00:00, which i would think is the datetime.minvalue...
But when i try to compare the above value with the dateTime.MinValue its false.. Is there a best practice to check for 'empty' dates in umbraco using API...
Okay, that's a bit strange.
I just did this in code:
DateTime input = System.Xml.XmlConvert.ToDateTime("0001-01-01T00:00:00");
Boolean same = (input == DateTime.MinValue);
And same ended up being true, so I wonder why you're not getting the same result.
is working on a reply...