Recently, I started exploring Sitecore Powershell Extensions (SPE). It's a masterpiece :).
I have a task of content loading from XML files. I was able to complete the whole logic and loading in less than 4 hours with additional couple of hours for learning SPE.
I struggled a bit while updating the DateTime fields and this post is to share what I have learned. I was initially parsing some 'yyyyMMddHHmmss' format string to datetime in SPE and assigned to a DateField of a news item. Item is updated successfully. But when I see the item in content tree it displays as below.
After some bing search, tried using raw views as the edit was successful.
I remembered Sitecore stores the time in Utc Iso format from Sitecore 8. So, started using Sitecore.DateUtil static class. This is what I have done
I have a task of content loading from XML files. I was able to complete the whole logic and loading in less than 4 hours with additional couple of hours for learning SPE.
I struggled a bit while updating the DateTime fields and this post is to share what I have learned. I was initially parsing some 'yyyyMMddHHmmss' format string to datetime in SPE and assigned to a DateField of a news item. Item is updated successfully. But when I see the item in content tree it displays as below.
I remembered Sitecore stores the time in Utc Iso format from Sitecore 8. So, started using Sitecore.DateUtil static class. This is what I have done
- Converted server time to Iso time
- Converted Iso time to Utc Iso time
- Updated date field with Utc Iso time
And this resolved the issue. Though Sitecore saves the Utc Iso time in DB, Sitecore client will actually display the local server time. So, applications developed in Sitecore must take care of how to handle the Iso Utc date fields for display in their applications.
Below is simple example to easily understand what happens by using Sitecore.DateUtil class
Thanks for sharing! This saved my time. :)
ReplyDeleteGlad it was helpful. :)
ReplyDeleteThanks for providing such an informative content.
ReplyDeleteISO Certification Consultancy Services in Bangalore
Thank you.. It was helpful
ReplyDeleteThank you! Very helpful...you saved me hours of research.
ReplyDelete