5

我有一个与此类似的 csv

"fundName","MMFcusip","ticker","AsOfDate","SumHoldingPercent"
"BlackRock OH Muni MMP/Instit","'091927236'","COIXX","2/29/2012 12:00:00 AM","100.00000000200"
"Western Asset Inst US Treas Res","'52470G841'","CIIXX","2/29/2012 12:00:00 AM","100.00000000200"

使用 powershell,如何在使用 import-csv cmdlet 时将“asOfDate”转换为日期/时间?

编辑:这是我目前正在使用的代码行

$measuredDate = $today.AddDays(-21)
$staleDates = Import-Csv d:\path\file.csv | Foreach-Object {$_.AsOfDate = Get-Date $_.AsOfDate} | Where-Object {asOfDate -lt $measuredDate} | Measure-Object
4

1 回答 1

5
Import-Csv file.csv |
Where-Object { ![string]::IsNullOrWhiteSpace($_.AsOfDate) } | 
Foreach-Object {
   $_.AsOfDate = $_.AsOfDate -as [datetime]
   $_
}
于 2012-05-14T14:47:48.800 回答