I have a CSV that contains a Scheduled Time (of day) but the value is in milliseconds from the start of day and I need to convert the values to time of day (0:HH:mm:ss,fff). This is how the CSV looks:
"Log Date","Scheduled Time","Category","Cart #","Scheduled Title","Actual Title","Start Date","End Date","Scheduled Length","Actual Length"
"7/18/2018 12:00:00 AM","22439181","DCM","3172","BONCHE URBANO DIGITAL 201","BONCHE URBANO COMERCIAL JUN 23","12/31/1969 7:00:00 PM","12/31/9999 11:59:59 PM","30","33"
"7/18/2018 12:00:00 AM","45750000","DCM","3172","BONCHE URBANO DIGITAL 201","BONCHE URBANO COMERCIAL JUN 23","12/31/1969 7:00:00 PM","12/31/9999 11:59:59 PM","30","33"
I have this and when I input the time into this, it works:
("{0:HH:mm:ss,fff}" -f ([datetime]([timespan]::fromseconds($time / 1000)).Ticks))
How can I use that to replace all the values in a CSV? I have this so far, but it doesn't work and I'm not great with Powershell to begin with.
Import-Csv .\Values.csv |
ForEach-Object {
$time = $_.'Scheduled Time'
$_.'Scheduled Time' = ("{0:HH:mm:ss,fff}" -f ([datetime]([timespan]::fromseconds($time / 1000)).Ticks));$_
} |
Export-Csv '.\Values.csv' -NoTypeInformation
Thanks in advance for the help!