Need help "Adding TIME"

Need help "Adding TIME"

Postby Jeff Barnes » Sat Jan 06, 2007 9:55 pm

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  Expand view

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

Re: Need help "Adding TIME"

Postby Enrico Maria Giordano » Sat Jan 06, 2007 10:35 pm

Code: Select all  Expand view
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
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Jeff Barnes » Sun Jan 07, 2007 12:20 am

My hat is off to you sir :D

Once again your solution works perfectly.

Thanks Enrico,


Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 64 guests