Albert,

Thanks! this will save me time when I begin to modify my updated database 
queries.


 
Jim Bentley,
American Celiac Society
1-504-737-3293


________________________________
 From: Albert Berry <[email protected]>
To: RBASE-L Mailing List <[email protected]> 
Sent: Wednesday, October 17, 2012 3:20 PM
Subject: [RBASE-L] - Re: DateTime tutorial
 
For anyone who would like to put this into a stored procedure, or test the 
math, here is my take on this. For a stored procedure you would need to change 
the "sho var" at the bottom, of course. If you remove the two datetime values, 
you can pass any two datetime values to the system.

------------------------------------------------------------------------------
-- DateDiff.pro
-- Returns the difference between two datetime entries
-- in hours, minutes and seconds
-- Albert Berry 2012/10/17
------------------------------------------------------------------------------
SET VAR vDateTime1 DATETIME = "10/14/2012 13:58:00"
SET VAR vDateTime2 DATETIME = "10/17/2012 14:12:03"
-- output variable
SET VAR vDateTimeDiff TEXT = NULL
-- working variables
CLEAR VAR vDifference, vHours, vDays, vMinutes, vSeconds
SET VAR vDifference INTEGER = (.vDateTime2 - .vDateTime1)
SET VAR vTimeSetting TEXT = (CVAL("TIME"))
SET VAR vTimeLength INTEGER = (SLEN(.vTimeSetting))
IF vTimeLength  > 9 THEN
    SET VAR vDifference = (NINT(.vDifference/1000)) -- round to nearest second
ENDIF
SET VAR vDays INTEGER = (INT(.vDifference/86400))
SET VAR vHours INTEGER = (INT(.vDifference/ 3600))
SET VAR vHours = (MOD(.vHours,24))
SET VAR vMinutes INTEGER = (INT((.vDifference - (.vDays*86400) - +
    (.vHours*3600))/60))
SET VAR vSeconds INTEGER  = (.vDifference - (.vDays * 86400) - +
    (.vHours * 3600) - (.vMinutes * 60))
SET VAR vDateTimeDiff = ( (CTXT(.vDays)) + "," + (CTXT(.vHours)) + +
    "," + (CTXT(.vMinutes)) + "," + (CTXT(.vSeconds)))
------------------------------------------------------------------------------
SHOW VAR vDateTimeDiff
RETURN

Albert

Reply via email to