Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Convert

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
I was trying to convert 150min to 2:30.
But I got error

Would you please help me?

code>>

set runTime 150
set runTimeMin [expr fmod($runTime,60)]
set runTimeHour [expr int($runTime,60)]

set fullRunTime "$runTimeMin : $runTimeHour"

puts $fullRuntime
 
set runTime 150
set runTimeMin [expr fmod($runTime,60)]
set runTimeHour [expr int($runTime)/60)]
--> I changed int($runTime.60) to int($runTime)/60

set fullRunTime "$runTimeMin : $runTimeHour"

puts $fullRuntime

this code works for me.

is it logically correct??
 
I bet you were getting an error to the effect "...not enough arguments for the the function", or something like that. Anyway, it's simple:

> set runTimeMin [expr int(fmod($runTime,60))]
> set runTimeHour [expr int($runTime/60)]
> set fullRunTime "$runTimeMin : $runTimeHour"

To get a little fancier, use the format cmd to make the hour and minute variables always be two digits (i.e. - 02:30).

> format "%02s" yourvariable
...where the arg flags "0" is for zero padding and "2" is the width.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top