formatting date time value

hi all,

given that $diff = this;

Days : 0
Hours : 1
Minutes : 44
Seconds : 29
Milliseconds : 429
Ticks : 62694298389
TotalDays : 0.0725628453576389
TotalHours : 1.74150828858333
TotalMinutes : 104.490497315
TotalSeconds : 6269.4298389
TotalMilliseconds : 6269429.8389

when I try to display the time in the following format, the values are empty. i can’t understand why.

$diff = (Get-Date) - $time
$stringToWrite = “{0:hh}:{1:mm}:{2:ss}” -f ($diff.hours), ($diff.minutes), ($diff.seconds)
$stringToWrite

hh:mm:ss

thanks!

You’re trying to extract hours, minutes, and seconds out of raw numbers. Do this instead

$stringToWrite = "{0:hh}:{0:mm}:{0:ss}" -f $diff
$stringToWrite

that was too easy :wink:

with the explanation, i now understand what i did wrong.

thank you!