casting column from csv as date powershell
casting, csv, date, powershell
Solution
Import-Csv file.csv |
Where-Object { ![string]::IsNullOrWhiteSpace($_.AsOfDate) } |
Foreach-Object {
$_.AsOfDate = $_.AsOfDate -as [datetime]
$_
}
Problem
I have a csv that is similar to this ``` "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 ``` $measuredDate = $today.AddDays(-21) $staleDates = Import-Csv d:\path\file.csv | Foreach-Object {$_.AsOfDate = Get-Date $_.AsOfDate} | Where-Object {asOfDate -lt $measuredDate} | Measure-Object ```