rpp

How does one use the DATETIME data.

I need to figure how much time has elapsed between two date time stamps

IN: 10/08/2007 08:52:47 AM

OUT: 10/08/2007 12:11:33 PM

Is there an easy formula to provide the exact hours and minutes

Richard

### Re: How to determine time elapsed between 2 DATETIME()'s

dni

d1 = DATETIME(2007,10,08,08,52,47)

d2 = DATETIME(2007,10,08,12,11,33)

difference is 11926 seconds (d2-d1).

### Re: How to determine time elapsed between 2 DATETIME()'s

CetinBasoz

abs(m.tValue1 - m.tValue2)

gives the difference between two datetime values in seconds. Adding a numeric to a datetime value means to add N seconds to that datetime value. In other words, for datetime + and - operators are overloaded.

Code Block

ltIn = datetime(2007,10,8,8,52,47)

ltOut = datetime(2007,10,8,12,11,33)

lnSecondsElapsed = abs(m.ltOut - m.ltIn)

If it doesn't span a day then you can also get a time string like:

Code Block

set hours to 24

ttoc( ctot("0") + abs(m.ltOut - m.ltIn), 2 )

Or in case it spans days:

Code Block

lcResult = ;

Right(Ttoc(Ctot('0') + Abs(m.ltOut-m.ltIn),1),6),"@R 9999 99:99:99")

* or

lcResult = ;
Right(Ttoc(Ctot('0') + Abs(m.ltOut-m.ltIn),1),4),"@R 99999:99:99")

### Re: How to determine time elapsed between 2 DATETIME()'s

rpp

Thanks very much,

I was able to use " ttoc( ctot("0") + abs(m.ltOut - m.ltIn), 2 )"

is there a way now to add multiple times that have been produced from the results

to show total hours worked

thanks

### Re: How to determine time elapsed between 2 DATETIME()'s

Naomi Nosonovsky

Your question is a bit unclear. Do you have different time intervals and you want to show several time intervals If yes, then you would have to create a string with the information. Use chr(13)+chr(10) to create carriage return.

### Re: How to determine time elapsed between 2 DATETIME()'s

CetinBasoz

Create Cursor multipleTimes (In T, Out T)

Rand(-1)

In = Datetime(2007,1,1,8,0,0)

Out = m.in + Int(Rand()*3600*5)

For ix = 1 To 20

Insert Into multipleTimes From Memvar

In = m.Out + Int(Rand()*86400)

Out = m.in + Int(Rand()*3600*5)

Endfor

Select In, Out, GetTimeElapsed(Out,In) As period From multipleTimes Into Cursor xx

Browse Nowait

Local Array aTotalSeconds

Select Sum(Round(Out-In,0)) From multipleTimes Into Array aTotalSeconds

GetTimeElapsed(aTotalSeconds)

Function GetTimeElapsed(t1,t2)

If Type('m.t1') = 'N'

Return ;

Right(Ttoc(Ctot('0') + m.t1,1),6),"@R 9999 99:99:99")

Else

Return ;

Right(Ttoc(Ctot('0') + Abs(m.t2-m.t1),1),6),"@R 9999 99:99:99")

Endif

Endfunc

### Re: How to determine time elapsed between 2 DATETIME()'s

MarciaAkins rpp wrote:
 I need to figure how much time has elapsed between two date time stamps IN: 10/08/2007 08:52:47 AM OUT: 10/08/2007 12:11:33 PM Is there an easy formula to provide the exact hours and minutes

*-- Given a number of seconds between two DatTimes, returns a parameter onject containing the number of days, hours, minutes and second

FUNCTION GetElapsedTime( tnElapsedSeconds )

LOCAL loObject

loObject = CREATEOBJECT( 'Line' )

WITH loObject

.AddProperty( 'nDays', INT( tnElapsedSeconds / 86400 ) )

.AddProperty( 'nHours', INT(( tnElapsedSeconds % 86400 ) / 3600 ) )

.AddProperty( 'nMins', INT(( tnElapsedSeconds % 3600 ) / 60 ) )

.AddProperty( 'nSecs', INT( tnElapsedSeconds % 60 ) )

ENDWITH

RETURN loObject

ENDFUNC