Author Posts

January 3, 2017 at 1:46 am

I have a bunch of Dates and times that I think are just strings.

$data | Select DateAdded
5/20/2015 8:27:34 AM
7/13/2016 8:10:58 AM
6/04/2012 12:10:58 PM

Wanting to sort would give me:

$data | Select DateAdded | Sort DateAdded
5/20/2015 8:27:34 AM
6/04/2012 12:10:58 PM
7/13/2016 8:10:58 AM

But what I want is:

6/04/2012 12:10:58 PM
5/20/2015 8:27:34 AM
7/13/2016 8:10:58 AM

How can I get it to sort using the Year Month Day Time?

Thanks!
Scott

January 3, 2017 at 1:54 am

$data | Select-Object -Property  @{Name='Date';Expression={Get-Date $_.DateAdded}} | Sort-Object -Property Date

January 3, 2017 at 3:18 pm

Thanks, this worked great. I think my hangup was thinking the Get-Date was only to get the current date/time and not actually setting something as a date/time object.

Thanks for the help!