a = DATETIME() gives the current date and time, to the nearest second, as a variable of Datetime type.
b = DATETIME(2018, 6, 28, 8, 15) gives a specific time and date, of Datetime type.
Subtracting one datetime from another gives the difference in seconds:
Secs = b - a
To convert to hours minutes and seconds, divide by 3600 (this gives you the number of hours), then divide the remainder by 60 (gives minutes), and the final remainder is the number of seconds.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
By the way, it is advisable not to use single letters between a and j as variable names. The reason is that they might clash with the built-in single-letter table aliases. In practice, it will very rarely cause a problem, but most developers try to avoid it.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
And besides computing the elements of the time difference, an easy way to get from Seconds to HH:MM:SS is, of course, adding these seconds to a default date, eg:
Because you can not only get the diff in seconds, you can also add seconds to a DateTime to get another one. And if you do so for a DateTime at midnight, the time portion is exactly what the seconds turn to in hours, minutes and seconds, especially in SET HOURS TO 24 mod without AM/PM display this works for essential differences below a day. Enough for example for appointment durations, working time logging etc.
In the end, store DateTimes of the points in time involved for your case, and you'll always be able to compute differences and display them in a human-readable format.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.