1

I'm working with a SharePoint list and it's common date/time format is 2020-01-06T08:09:00.0000000Z. I have source date that I'm writing to that list that's in another format, i.e. 11.07.2012 09:40.

How can I convert that string into the format that the SharePoint list expects?

Closest I've come is:

[datetime]$dateToConvert = "11.07.2012 09:40" Get-Date -Date $dateToConvert -Format FileDateTimeUniversal

which outputs 20121107T0840000000Z but that's missing the dashes.

Any ideas?

1
  • 3
    Try with -Format o Commented Jan 6, 2020 at 9:41

1 Answer 1

2

You can try this: $dateToConvert.ToUniversalTime().ToString("o")

  • ToUniversalTime() to get the "Z" at the end (instead of the UTC offset)
  • ToString("o") to get a string that complies with ISO 8601
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't work with PS 5.1, is this a new feature i PS 6.0?
@MokiTa Might be your .Net that is out of date. Here is the Microsoft documentation for ToUniversalTime() Link
Putting [datetime] in front of the variable makes it work for me.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.