我有一个文件data.csv,其中包含:
2017.11.1,09:55,1.1,1.2,1.3,1.4,1
2017.11.2,09:55,1.5,1.6,1.7,1.8,2
我想在昨天的日期过滤它,所以我这样做了:
$Data = Import-Csv $file -Header Date,Time,A,B,C,D,E
$CutOff = (Get-Date).AddDays(-1)
$Data2 = $Data | Where-Object {$_.Date -as [datetime] -gt $Cutoff}
$Data2 | Export-Csv -Path "Date2.csv"
但是文件data2.csv包含:
#TYPE System.Management.Automation.PSCustomObject
"Date","Time","A","B","C","D","E"
"2017.11.2","09:55","1.5","1.6","1.7","1.8","2"
其格式与原始格式不同: