# Time (seconds past midnight)

Posted by goo on 14-Mar-2018 07:12

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...?

Posted by Roger Blanchard on 14-Mar-2018 07:23

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')

Posted by Richard.Kelters on 15-Mar-2018 02:47

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

Posted by Roger Blanchard on 14-Mar-2018 07:21

have you looked at INTERVAL?

Posted by Roger Blanchard on 14-Mar-2018 07:23

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')

Posted by bstaunton on 14-Mar-2018 07:27

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).

Posted by Brian K. Maher on 14-Mar-2018 07:28

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

Posted by George Potemkin on 14-Mar-2018 07:50

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.

Posted by Peter Judge on 14-Mar-2018 08:09

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.

Posted by Stefan Drissen on 14-Mar-2018 08:33

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

Posted by goo on 14-Mar-2018 16:03

Thanks, white waiting I did the string hh:mm:ss entry way.... works, but I liked the interval way best, closer to System.datetime way :-) Thanks

Posted by Richard.Kelters on 15-Mar-2018 02:47

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.