Need help "Adding TIME"

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Need help "Adding TIME"

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Need help "Adding TIME"

Post 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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

My hat is off to you sir :D

Once again your solution works perfectly.

Thanks Enrico,


Jeff
Post Reply