0

I have an issue with SharePoint date time field.

Basically I have a date time field, and this field contains for example 19/12/2014 11:30:00. I would like to get this date and remove the time part, so i have then 19/12/2014 00:00:00, but when i set 2014-01-12T00:00:00Z, and i try to retrieve it later, i get 1/12/2014 1:00:00 AM, so i have no idea where this 1AM comes from.

Any idea? Here is the script how i do it

$nDate = new-object System.DateTime ($dateTime.Year, $dateTime.Month, $dateTime.Day);
$date = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime($nDate)
$item["DateTimeField"]= $nDate;
$item.SystemUpdate($false);

Thanks

1
  • Do you retrieve it and parse it to ISO8601 again, to eliminate time zones etc? Commented Dec 19, 2013 at 8:51

1 Answer 1

3

The SPUtility.CreateISO8601DateTimeFromSystemDateTime is an extremely badly coded DateTime format function.

It has a hard requirement that the DateTime passed to it is in UTC as it just hardcoded adds Z as the zone designator.

So you have to convert your DateTime to UTC using mySite.RegionalSettings.TimeZone.LocalTimeToUTC(date) or some other method before calling it.

See Converting Date and Time Values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.