将csv中的列转换为日期powershell [英] casting column from csv as date powershell
本文介绍了将csv中的列转换为日期powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个与此相似的csv
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"
使用powershell,如何在使用import-csv cmdlet时将"asOfDate"转换为日期/时间?
Using powershell, how can I cast the "asOfDate" as a date/time when using the import-csv cmdlet?
这是我目前正在使用的代码行
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
推荐答案
Import-Csv file.csv |
Where-Object { ![string]::IsNullOrWhiteSpace($_.AsOfDate) } |
Foreach-Object {
$_.AsOfDate = $_.AsOfDate -as [datetime]
$_
}
这篇关于将csv中的列转换为日期powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文