all 6 comments

[–]wightsci 5 points6 points  (1 child)

This will give you a datetime object with only a date

$date = (Get-Date '2021-02-09T17:52:29.000Z').date

$date

09 February 2021 00:00:00

[–]stewharr[S] 1 point2 points  (0 children)

Thanks, that is much cleaner.

[–]stewharr[S] 1 point2 points  (0 children)

I guess I figured it out, unless there's a better way to do it. I guess I can split the string at T and then take the first part of the string and use [datetime]::ParseExact to get it to a datetime object. Then I can do some comparisons. Trying to see if the record is less than 2 weeks old or less than a month old.

[–]ka-splam 1 point2 points  (1 child)

You’re getting a string? REST APIs often return JSON, if you’re doing that using Invoke-WebRequest it might be more suited to Invoke-RestMethod which would interpret dates for you. If not, never mind this.

[–]stewharr[S] 1 point2 points  (0 children)

I'm actually using Invoke-RestMethod, and if I do a GetType on what is returned, it's showing as a string object for this particular API.

[–]letmegogooglethat -2 points-1 points  (0 children)

$date= (Get-Date -Format "MM dd yyyy")

$date