简体   繁体   中英

Change date format in CSV using PowerShell

I'm new to PowerShell and I have a CSV file where I need to change the format of the dates in 2 columns (as shown in the example below) to the format dd/mm/yyyy.

"First Name","Last Name","Employee Number","Course Name","Completion Status","Date_Started","Completion_Date"

Joe,Bloggs,8632,"Test Name",Complete,"26 Nov 2015","26 Nov 2015"

Does anyone know how to achieve this using PowerShell?

You can try this :

Import-Csv D:\temp\test.csv | % {$_.Date_Started = ([datetime]($_.Date_Started)).ToString('dd/MM/yyyy');$_.Completion_Date = ([datetime]($_.Completion_Date)).ToString('dd/MM/yyyy');$_} | Export-Csv 'D:\temp\testBis.csv' -NoTypeInformation

You can try [datetime]::ParseExact(...) to parse special dates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM