Logic Machine Forum
Calculate number of minutes until a future date/time - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Calculate number of minutes until a future date/time (/showthread.php?tid=4690)



Calculate number of minutes until a future date/time - CarlS - 29.03.2023

I have this info from two group-adresses 3-byte time/day and three byte date
This is a date and time several days ahead for the start of a meeting
I want to calculate the number of minutes from "now" until the date/time in this two group-addresses, but I can't figure out how to do it...


Code:
Event for CUE Starttid (0/1/20) 29.03.2023 21:54:04
* arg: 1
  * string: startdate
* arg: 2
  * table:
   ["day"]
    * number: 2
   ["year"]
    * number: 2023
   ["month"]
    * number: 4
Event for CUE Starttid (0/1/20) 29.03.2023 21:54:04
* arg: 1
  * string: starttime
* arg: 2
  * table:
   ["day"]
    * number: 7
   ["minute"]
    * number: 0
   ["second"]
    * number: 0
   ["hour"]
    * number: 11
   ["min"]
    * number: 0
   ["sec"]
    * number: 0



RE: Calculate number of minutes until a future date/time - admin - 30.03.2023

Try this:
Code:
time = grp.getvalue('0/0/1')
date = grp.getvalue('0/0/2')

-- merge tables
for k, v in pairs(date) do
  time[ k ] = v
end

seconds = os.time(time) - os.time()
minutes = math.round(seconds / 60)

log(minutes)



RE: Calculate number of minutes until a future date/time - CarlS - 30.03.2023

Magic Shy
Thank you very much.