Share via


Convert Date Format of a custom attribute from yyyy/MM/dd to MM-dd-yyyy

Question

Monday, May 7, 2018 6:57 PM

I'm trying to convert the date format of two attributes to MM-dd-yyyy.

Here's what I get when I select both attitudes that I am trying to convert. (this works)

Get-ADUser -Filter {name -like "*mike*"} -Properties * | Select created,saphiredate

created                saphiredate
               
2003-01-17 10:23:06 PM 1989/10/16

*********************

Here's what I get when I convert the "Created" attribute to "MM-dd-yyyy" (this works)

Get-ADUser -Filter {name -like "*mike*"} -Properties * | Select @{Label="Hire Date";Expression={($_.created).ToString('MM-dd-yyyy')}}

Hire Date

01-17-2003

*********************

Here's what I get when I convert the "saphiredate" attribute to "MM-dd-yyyy" (this does not work and returns a blank value)

Get-ADUser -Filter {name -like "*mike*"} -Properties * | Select @{Label="Hire Date";Expression={($_.saphiredate).ToString('MM-dd-yyyy')}}

Hire Date