Handling SharePoint DateTime columns
Posted on 2013-05-16
I am not sure how to handle properly with Powershell the SharePoint columns that are of type DateTime. I have 3 DateTime fields that differ slightly as follows but I notice the handline has to be separately done.
"Expiry Date" : A DateTime column that always have a value.
"Renewal Date" : A DateTime column that can have null.
"Notification Date" : A calculated column that returns Date only.
In Powershell, if I use
[DateTime] tmpDate = $item["Expiry Date"] --> this works
[DateTime] tmpDate = $item["Renewal Date"] --> this fail with cannot convert null to DateTime
[DateTime] tmpDate = $item["Notification Date"] --> this fails because it is not recognized as a date. Instead it is a string result, e.g. "datetime;#2005-01-26 00:00:00"
This is confusing. What is then the correct way to retrieve a date column from a SharePoint List?