Project: | The Progress STandard Libraries (STL) |
Component: | Code |
Category: | feature request |
Priority: | normal |
Assigned: | alon.blich |
Status: | active |
Is there a logic in your standard libeary for calculating the difference between start time and end time....
I have 4 parameters.... start date, end date, start time and end time....
Need help...
Comments
#1
Hi Divya,
I just had last week the same request and I programmed myself this little function. It's easy now to calculate a difference.
FUNCTION icVirtualTimeInSec returns integer
( pdDate as date,
pcTime as character ) :
/* Description ---------------------------------------------------------------*/
/* */
/* returns a number of seconds since 1/1/2000 */
/* */
/* Notes ---------------------------------------------------------------------*/
/* */
/* */
/* */
/* Parameters ----------------------------------------------------------------*/
/* */
/* pdDate - date value */
/* pcTime - char value with format hh:mm:ss */
/* */
/* Examples ------------------------------------------------------------------*/
/* */
/* */
/* */
/*----------------------------------------------------------------------------*/
return (pdDate - 01/01/2000) * 24 * 60 * 60
+ integer (entry (1, pcTime, ':':U)) * 60 * 60
+ integer (entry (2, pcTime, ':':U)) * 60
+ integer (entry (3, pcTime, ':':U))
.
end function. /* icVirtualTimeInSec */
Regards,
Gunnar
#2
Thanks Gunnar
#3
You might want to convert your DATE and TIME parameters to a DATETIME datatype, and the calculate the difference using the INTERVAL function (this example assumes your TIME string to be HH:MM or HH:MM:SS or HH:MM:SS,SSS)
FUNCTION TimeInterval RETURNS INTEGER ( FromDate AS DATE,
FromTime AS CHARACTER,
ToDate AS DATE,
ToTime AS CHARACTER):
RETURN INTERVAL ( DATETIME ( SUBSTITUTE("&1 &2",FromDate,FromTime) ) ,
DATETIME ( SUBSTITUTE("&1 &2",ToDate ,ToTime) ) , "seconds").
END FUNCTION.
#4
Sure. Have a look at slib/date_intervaltime (compatible with any Progress version).
define var tHiDate as date no-undo.
define var iHiTime as int no-undo.
define var tLoDate as date no-undo.
define var iLoTime as int no-undo.
assign
tHiDate = today
iHiTime = 3 * 60 * 60 /* 3:00 am */
tLoDate = today - 1
iLoTime = 19 * 60 * 60. /* 7:00 pm */
message
string( {slib/date_intervaltime tHiDate iHiTime tLoDate iLoTime}, "hh:mm:ss" )
view-as alert-box.
#5
If you need to convert strings to date and time values here are a few samples from the standard libraries.
{slib/slibdate.i}
define var tDate as date no-undo.
define var iMTime as int no-undo.
define var iTimeZone as int no-undo.
run date_str2date(
input "31/12/2000 10:35:10",
input "dd/mm/yyyy hh:ii:ss",
output tDate,
output iMTime,
output iTimeZone ).
message
tDate skip
string( int( iMTime / 1000 ), "hh:mm:ss" )
view-as alert-box.
run date_str2date(
input "10:35:10",
input "hh:ii:ss",
output tDate,
output iMTime,
output iTimeZone ).
message
tDate skip
string( int( iMTime / 1000 ), "hh:mm:ss" )
view-as alert-box.
run date_str2date(
input "Thursday, Feb 24 2011 10:35:10",
input "wwwww, mmm dd yyyy hh:ii:ss",
output tDate,
output iMTime,
output iTimeZone ).
message
tDate skip
string( int( iMTime / 1000 ), "hh:mm:ss" )
view-as alert-box.
#6
Thanks Alon,
but I was looking for calculating the difference b/w 2 times..... esp when they the start date and end date are different....
I surfed thro' ure library ....couldn't find one....
#7
ok.
try the first post about {slib/date_intervaltime}.
if you need to convert string time like hh:mm:ss to seconds integer try the second post about date_str2date( ).
hope this helps and thanks for using the standard libraries.
#8
I have this old routine as follows:-
def var time-in as int. /* this can be a field
def var time-out as int. on a table */
def var time-elapse as char format "x(8)".
time-in = time.
display string(time-in, "hh:mm:ss").
time-out = time.
display string(time, "hh:mm:ss").
time-elapse = string((time-out - time-out), "hh:mm:ss").
display time-elapse.
Errol
#9
Sorry the first one have typing error.
I have this old routine as follows:-
def var time-in as int. /* this can be a field
def var time-out as int. on a table */
def var time-elapse as char format "x(8)".
time-in = time.
display string(time-in, "hh:mm:ss").
time-out = time.
display string(time, "hh:mm:ss").
time-elapse = string((time-out - time-in), "hh:mm:ss").
display time-elapse.
Errol