Time difference between two dates

make

Member
Hello,

iam looking for a function in progress, that returns the the difference between two dates in Seconds´, for example:

First date : time:
12.11.2003 08:18:11

Second date: time:
12:11:2003 09:04:18

Is there a function for this problem in Progress ?

Greets

Make
 
As long as the difference between the two dates isn't greater than about 68 years (progress cannot store ints greater than 2^31) the following should do it:

Code:
assign
	iSecs = (dDateA - dDateB) * 60 * 60 * 24 - iTimeB + iTimeA.
 

Steele

New Member
Format

make said:
iam looking for a function in progress, that returns the the difference between two dates in Seconds´, for example:

First date : time:
12.11.2003 08:18:11

Second date: time:
12:11:2003 09:04:18

Is there a function for this problem in Progress ?

Make

Is this in a character format or are you pulling the time as an integer and the dates as date?

If it is in a character format, you will have to strip the hours, minutes, and seconds.

I am going to assume that your dates are in date format since most Progress programmers utilize it, except for one company I worked for in the past who insisted on storing it as a character sometimes.

v-date1 and v-date2 are date fields.
v-time1 and v-time2 as character fields.
v-timediff is defined as an integer.

v-timediff = (v-date2 - v-date1) * 86400 + calcsecs(v-time2) - calcsecs(v-time1).

function calcsecs returns integer (v-time as character) :
define variable hh as integer no-undo.
define variable mm as integer no-undo.
define variable ss as integer no-undo.

assign
hh = integer(substring(v-time,1,2))
mm = integer(substring(v-time,4,2))
ss = integer(substring(v-time,7,2)).
return hh * 3600 + mm * 60 + ss.
end function.

I hope this helps,

Randy
 
Top