Ty.
Ty.

Reputation: 187

Import-CSV Find How Many Minutes Has Passed

I would like to eventually go from csv to html. I have done something similar before, but need to get one step done before the data is ready. I need to get the start time, instead of in time, but in elapsed minutes.

When I bring in the data, one of the columns is formatted like this:

mSTART:
2012-08-07 15:58:57.043
2012-08-07 11:00:45.350
2012-08-07 15:54:47.870
2012-08-07 15:44:28.557

I would like to manipulate that data into a column that says.

Duration:
38 minutes
70 minutes
108 minutes

It would be [(now)-(the start time)] in minutes.

My current import-csv line looks like this:

import-csv .\mydata.csv -header mID, mDES, mTYPE, mVAL, mSTART, mEFF, mDT, mDTDES | Select mDES, mSTART, @{Name="DT";Expression={ $_.mDT+" - "+$_.mDTDES}}

Upvotes: 0

Views: 178

Answers (1)

zdan
zdan

Reputation: 29450

Turn the text in your date column into a date object using the get-date commandlet.

Just subtract that result from the current time, which returns a timespan object. If you just want the minutes elapsed, call the TotalMinutes property on that object.

import-csv .\mydata.csv -header mID, mDES, mTYPE, mVAL, mSTART, mEFF, mDT, mDTDES | 
    Select mDES, mSTART, @{Name="DT";Expression={ $_.mDT+" - "+$_.mDTDES}, @{Name="Duration";Expression={ ((get-date) - (get-date $_.mStart)).TotalMinutes} }

Upvotes: 1

Related Questions