Convert seconds into hours and minutes. How? - old forum post


#1

andydaoust

Joined on 06-02-2005
Posts 1
ioControl, Convert a float variable (seconds) into Hours and minutes

I have a float variable that represents seconds. I would like to convert that into 2 variables, whole hours and minutes (0.0 minutes). I think I must determine what the value is to the left of the decimal point so I can know the number of whole hours. 7500 seconds / 3600 = 2.0833 hours (2.0833 hours - 2 ) * 60 = 5 minutes My ultimate goal is to show the remaining time counting down on ioDisplay. Anyone have any help or hints? Thank You, Andy
Report
06-03-2005, 1:17 PM
felmleed

Joined on 11-26-2003
Posts 1
Re: ioControl, Convert a float variable (seconds) into Hours and minutes

To resolve the number of minutes, try the Modulo command (see Command Reference) as part of a two step process.

  1. nTempVar = 7500 Modulo 3600
  2. nSeconds = nTempVar / 60 Using optoscript: nSeconds = ( 7500 % 3600 ) / 60
    To resolve the hours, divide the number of seconds by 3600 with the destination variable being an integer.
    This effectively rounds the value down to the lowest integer.