Solved

Handling SharePoint DateTime columns

Posted on 2013-05-16
1
1,077 Views
Last Modified: 2013-06-24
Hi Experts,

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?
0
Comment
Question by:NicksonKoh
1 Comment
 
LVL 18

Accepted Solution

by:
x-men earned 500 total points
ID: 39174956
if ($item["Renewal Date"] -ne "") {[DateTime] tmpDate = $item["Renewal Date"]}
[DateTime] tmpDate = get-date ($item["Notification Date"])
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question