Count Your Work: Calculating Process Runtime

by Sep 1, 2009

Each process stores its start time, so it is fairly easy to find out when the process was launched. If you'd like to know when you started your PowerShell session, try this:

(get-process -id $pid).StartTime

And if you'd rather like to find out how long you have been working, feed the start time to New-Timespan which compares it against the current time and returns the time difference:

new-timespan (get-process -id $pid).StartTime
"You worked for $((new-timespan (get-process -id $pid).StartTime).TotalHours) hours now!"

Twitter This Tip! ReTweet this Tip!