简体   繁体   English

使用PowerShell更改CSV中的日期格式

[英]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. 我是PowerShell的新手,我有一个CSV文件,在其中需要将2列中的日期格式(如下例所示)更改为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? 有谁知道如何使用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. 您可以尝试[datetime]::ParseExact(...)解析特殊日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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