Question:
I have a csv that is similar to this
1 2 3 4 |
"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" |
Using powershell, how can I cast the “asOfDate” as a date/time when using the import-csv cmdlet?
EDIT: this is the line of code that I’m currently working with
1 2 3 |
$measuredDate = $today.AddDays(-21) $staleDates = Import-Csv d:\path\file.csv | Foreach-Object {$_.AsOfDate = Get-Date $_.AsOfDate} | Where-Object {asOfDate -lt $measuredDate} | Measure-Object |
Answer:
1 2 3 4 5 6 7 |
Import-Csv file.csv | Where-Object { ![string]::IsNullOrWhiteSpace($_.AsOfDate) } | Foreach-Object { $_.AsOfDate = $_.AsOfDate -as [datetime] $_ } |