Converting Date & Time Value when using import-csv

Hello

I am trying to import csv from user process data I generated.

One of the fields is called CreationDate & contains a time and date format like this 31/03/2015 15:53:52, I want to convert it to just a date format dd/mm/yyyy.

This is what I have so far but I struggling getting the CreationDate converted to dd/mm/yyyy

$data = Import-Csv -Path $csv | ForEach-Object {$_.CreationDate = get-date -Format 'dd/MM/yyyy'}

This gets me the dates but is missing the rest of the fields

$data = Import-Csv -Path $csv | ForEach-Object {[datetime]::Parse($_.CreationDate).ToString('MM/dd/yyyy')}

Thank you in adavnce

Steve


  • Edited by Steve_99 21 hours 51 minutes ago
June 30th, 2015 5:17am

Hi Steve,

you can use select-object for this:

$data = Import-Csv -Path $csv | Select-Object *,@{ N = "DateFormatted"; e = { [datetime]::Parse($_.CreationDate).ToString('MM/dd/yyyy') } }

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 5:29am

Thank you Fred that works perfeclty I never thought of using the select-object to get the data.

Thank you

Steve

June 30th, 2015 5:50am

Glad to be of assistance, Steve :)

Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 6:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics