Time (seconds past midnight) - Forum - OpenEdge General - Progress Community

# Time (seconds past midnight)

Forum

#### Time (seconds past midnight)

11.7

What is the "best" way of getting Hours and Minutes from TIME function?

I understand that I can do a string(time,'hh:mm') and then do a entry(1..... but is there another way i.e. .System...?

• INTERVAL (DATETIME (MONTH(TODAY), DAY (TODAY), YEAR (TODAY), 0, 0, 0), NOW, 'hours')

INTERVAL (DATETIME (MONTH(TODAY), DAY (TODAY), YEAR (TODAY), 0, 0, 0), NOW, 'minutes')

• The interval parameters maybe date, datetime or datetime-tz therefore you can do:

define variable Minutes as integer no-undo.

Minutes = interval(now,today,"minutes").

Makes it more readable then the first interval suggestion.

All Replies
• have you looked at INTERVAL?

• INTERVAL (DATETIME (MONTH(TODAY), DAY (TODAY), YEAR (TODAY), 0, 0, 0), NOW, 'hours')

INTERVAL (DATETIME (MONTH(TODAY), DAY (TODAY), YEAR (TODAY), 0, 0, 0), NOW, 'minutes')

• I think this would work

DEFINE VARIABLE theTimeHours    AS INTEGER NO-UNDO.

DEFINE VARIABLE theTimeMinutes AS INTEGER NO-UNDO.

theTimeHours = TRUNCATE(TIME / 3600,0).  /* To get the current hour e.g 12pm */

theTimeMinutes = (TIME / 60) MODULO 60. /* To get the remainder of minutes after the hour */

DISPLAY SUBSTITUTE("&1:&2",theTimeHours,theTimeMinutes).

• To be 100% safe, store the result of TODAY in a variable and use the variable in the code Roger gave you.

• Why INTERVAL is the "best" way? It needs at least two system calls (the ones behind TODAY and NOW).

And INTERVAL is a bit (negligibly though) slower than ASSIGN vHours = TIME vHours = TRUNCATE(vHours / 3600, 0).

And (most importantly) INTERVAL is a less readable solution.

• Maybe only speaking for myself, but it’s less (human) work – no need to figure out how many seconds in an hour or whatnot … ie lazy programmer reasons.
• The interval solution looks so twisted to my human eyes that it would need to hide behind a function facade - in which case the function might as well be doing old school modulo 60 tricks as George started:

def var itime as int.

itime = time.

message

string( itime, "hh:mm:ss" ) skip (1)

"h~t" truncate( itime / 3600, 0 ) modulo 60 skip

"m~t" truncate( itime / 60, 0 ) modulo 60 skip

"s~t" itime modulo 60