Page 1 of 1

Need help "Adding TIME"

Posted: Sat Jan 06, 2007 9:55 pm
by Jeff Barnes
Hi Everybody,

I need a function that will allow me to add seconds to a stored time.

I need to create a loop that will add 4 seconds to each record in the file.

Something like:

Code: Select all


cTime := "12:10:58" 
GO TOP
DO WHILE ! EOF()
   MyDbf->TimeField := cTime
   cTime = cTime + 4seconds  //This is where I need help
   SKIP
ENDDO

I need to make sure that it will adjust the minutes or hours as they pass over 60 seconds (or 60 minutes etc...)

Any Ideas?

Thanks
Jeff

Re: Need help "Adding TIME"

Posted: Sat Jan 06, 2007 10:35 pm
by Enrico Maria Giordano

Code: Select all

FUNCTION MAIN()

    LOCAL cTime := TIME()

    ? cTime, ADDSECONDS( cTime, 4 )

    RETURN NIL


STATIC FUNCTION ADDSECONDS( cTime, nSec )

    LOCAL nHour, nMin

    nSec = ( VAL( LEFT( cTime, 2 ) ) * 3600 + VAL( SUBSTR( cTime, 4, 2 ) ) * 60 + VAL( RIGHT( cTime, 2 ) ) + nSec ) % 86400

    nHour = INT( nSec / 3600 )

    nSec -= nHour * 3600

    nMin = INT( nSec / 60 )

    nSec -= nMin * 60

    RETURN STRZERO( nHour, 2 ) + ":" + STRZERO( nMin, 2 ) + ":" + STRZERO( nSec, 2 )
EMG

Posted: Sun Jan 07, 2007 12:20 am
by Jeff Barnes
My hat is off to you sir :D

Once again your solution works perfectly.

Thanks Enrico,


Jeff