Taking next run from another script

Friends, I’m writing a script that takes the NEXT RUN from another script. Using the HOTSPOT limit-uptime. I’m using version 6.49.18. This is script


Thank you very much in advance for your help.

Friends, I have realized that the problem is when the LIMIT-UPTIME is 1d 00:00:00, how can I convert it into a date and time?

Thank you for your help

Assuming you’re talking about a recent V7, state-date= allows a time type (which limit-update is), so you can just add your $limitUpdate to value of [:timestamp] (which “now” in a time type, but that including the date since it’s not a relative time like limit-ypdate).

So you can then just add any “time” value (like your limitUptime) to the :timestamp to get a future start-date. No string types or :pick required.

/system/scheduler … start-date=([:timestamp]+$limitUptime)

Now I’m not sure it just would be have been easier to have an interval that does a check, RATHER than add/removing scheduled item. Also the add/remove scheduler items are config writes, so over time, you modifying the config a bunch of time on flash (which may not be too significant, but that depend on your hotspot limit and #user etc.)

Thanks for the reply, I’m using version 6.49.18.

Can someone help me? Thank you.

I need to get the date and time of the next script run. I use the following command:

{
:local nextRun [/system scheduler get [find where name="test"] next-run]
:put $nextRun
}

may/26 07:00:00

and I don’t get the full date
I use version 6.49.18
Can you help me please?

See here how to get timestamp from such date format.

Thanks for responding “OPTIO” but I haven’t found how to convert the interval=6w3d to a date

add interval=6w3d name=schedule1 on-event="/system rebbot" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=may/26/2025 start-time=07:59:27

I reviewed what you told me above and found this:

:local simplercurrdatetimestr do={
    /system clock
    :local vdate [get date]
    :local vtime [get time]
    :local vdoff [:toarray "0,4,5,7,8,10"]
    :local MM    [:pick $vdate ($vdoff->2) ($vdoff->3)]
    :local M     [:tonum $MM]
    :if ($vdate ~ ".../../....") do={
        :set vdoff [:toarray "7,11,1,3,4,6"]
        :set M     ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
        :if ($M>12) do={:set M ($M - 12)}
        :set MM    [:pick (100 + $M) 1 3]
    }
    :local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)]
    :local dd   [:pick $vdate ($vdoff->4) ($vdoff->5)]
    :local HH   [:pick $vtime 0  2]
    :local mm   [:pick $vtime 3  5]
    :local ss   [:pick $vtime 6  8]

    :return "$yyyy/$MM/$dd $HH:$mm:$ss"
}

:put [$simplercurrdatetimestr]

But I’m still the same.

Thank you for your help.

The instruments are all there.
http://forum.mikrotik.com/t/rextended-fragments-of-snippets/151033/1

Thanks for your response friend REX, but I am implementing it and the response obtained is 0

{
:local interval [/system scheduler get [find where name=TEST] interval]
:put $interval
:local interval do={
:local inTime $1
:local wPos [:find $inTime “w” -1]
:local dPos [:find $inTime “d” -1]
:local itLen [:find $inTime “.” -1] ; :if ([:typeof $itLen] = “nil”) do={:set itLen [:len $inTime]}
:local itSec [:pick $inTime ($itLen - 2) $itLen]
:local itMin [:pick $inTime ($itLen - 5) ($itLen - 3)]
:local itHou [:pick $inTime ($itLen - > :sunglasses: > ($itLen - 6)]
:local itDay 0
:local itWee 0
:if (([:typeof $wPos] = “nil”) and ([:typeof $dPos] = “num”)) do={:set itDay [:pick $inTime 0 $dPos] }
:if (([:typeof $wPos] = “num”) and ([:typeof $dPos] = “num”)) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = “num”) do={:set itWee [:pick $inTime 0 $wPos] }
:local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee))
:return $totitSec
}
:put [$interval]
}
6w3d08:10:00
0

:local interval [/system scheduler get [find where name=TEST] interval]
{… :put $interval
{… :local interval do={

and then how many times must it be written that IT IS WRONG TO USE VARIABLE NAMES THAT ARE THE SAME AS OBJECTS THAT ALREADY EXIST???

if you get “interval” you can not use the name “interval” for variable.

And really function and variable with same name???


My function is called timetoseconds if you change function structure and name, your business.


example on “your” 6w3d08:10:00

[example@6.48.7] > :put [$timetoseconds 6w3d08:10:00]
3917400

# to be sure if is missing hh:mm:ss better to convert on time format:
[example@6.48.7] > :put [$timetoseconds [:totime 6w3d]]
3888000

# after that, I add [:totime ] on main function post

Thanks my friend REX, now it works, but how do I convert those seconds into a future date and time to place it somewhere else?

add to current unix time the seconds from interval, and change back the unix time on date and time.

all functions to do that already exist on my repository

This is my friend REX.

/system clock
:global strDate [get date]
:global strTime [get time]
:global intGoff [:tonum [get gmt-offset]]
:if ($intGoff > 0x7FFFFFFF) do={:set intGoff ($intGoff - 0x100000000)}
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:global intYear   [:tonum [:pick $strDate 7 11]]
:global strMonth  ($arrMonths->[:pick $strDate 0 3])
:global strDay    [:pick $strDate 4 6]
:global strHour   [:pick $strTime 0 2]
:global strMinute [:pick $strTime 3 5]
:global strSecond [:pick $strTime 6 8]
:global strOffsig "+"
:global strGoff   $intGoff
:if ($intGoff < 0) do={:set strOffsig "-"; :set strGoff ($intGoff * -1)}
:global strHoff  [:pick [:totime $strGoff] 0 2]
:global strMoff  [:pick [:totime $strGoff] 3 5]
:global strISOdate "$intYear-$strMonth-$strDay\54$strHour:$strMinute:$strSecond$strOffsig$strHoff:$strMoff"
:put "$strDate $strTime $strOffsig$intGoff converted to ISO format is $strISOdate"

:global futuredatetimestr do={
/system clock
:local vdate [get date]
:local vtime [get time]
:local vgmt [:tonum [get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:local prMntDays [:toarray “0,0,31,59,90,120,151,181,212,243,273,304,334”]
:local daysOnMnt [:toarray “0,31,28,31,30,31,30,31,31,30,31,30,31”]
:local LcaseMnts [:toarray “0,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local PcaseMnts [:toarray “0,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec”]
:local UcaseMnts [:toarray “0,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC”]
:local LcaseWeekDays [:toarray “thu,fri,sat,sun,mon,tue,wed”]
:local PcaseWeekDays [:toarray “Thu,Fri,Sat,Sun,Mon,Tue,Wed”]
:local UcaseWeekDays [:toarray “THU,FRI,SAT,SUN,MON,TUE,WED”]
:local NumbrWeekDays [:toarray “4,5,6,7,1,2,3”]
:local Fzerofill do={:return [:pick (100 + $1) 1 3]}
:local gmtSg “+”; :if ($vgmt < 0) do={:set gmtSg “-”; :set vgmt ($vgmt * -1)}
:local gmtHr [:pick [:totime $vgmt] 0 2]
:local gmtMn [:pick [:totime $vgmt] 3 5]
:local vdoff [:toarray “0,4,5,7,8,10”]
:local MM [:pick $vdate ($vdoff->2) ($vdoff->3)]
:local M [:tonum $MM]
:if ($vdate ~ “…/../…”) do={
:set vdoff [:toarray “7,11,1,3,4,6”]
:set M ([:find “xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC” [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
:if ($M>12) do={:set M ($M - 12)}
:set MM [:pick (100 + $M) 1 3]
}
:local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)]
:local Leap “No-Leap”
:if ((($yyyy - 1968) % 4) = 0) do={:set Leap “Leap”; :set ($prMntDays->1) -1; :set ($prMntDays->2) 30; :set ($daysOnMnt->2) 29}
:local mmm ($LcaseMnts->$M)
:local Mmm ($PcaseMnts->$M)
:local MMM ($UcaseMnts->$M)
:local MD ($daysOnMnt->$M)
:local dd [:pick $vdate ($vdoff->4) ($vdoff->5)]
:local d [:tonum $dd] ; :local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($prMntDays->$M) + ($d - 1))
:local YD (($prMntDays->$M) + $d)
:local www ($LcaseWeekDays->($totd % 7))
:local Www ($PcaseWeekDays->($totd % 7))
:local WWW ($UcaseWeekDays->($totd % 7))
:local WD ($NumbrWeekDays->($totd % 7))
:local HH [:pick $vtime 0 2]
:local H [:tonum $HH]
:local hh ([:tonum $HH] % 12); :if ($hh = 0) do={:set hh 12}; :set hh [$Fzerofill $hh]
:local h [:tonum $hh]
:local a “A”; :if ([:tonum $HH] > 11) do={:set a “P”}
:local aa “$a\4D”
:local mm [:pick $vtime 3 5]
:local m [:tonum $mm]
:local ss [:pick $vtime 6 8]
:local s [:tonum $ss]
:local Z “$gmtSg$gmtHr:$gmtMn”
:local Unix (((((($totd * 24) + $H) * 60) + $m) * 60) + $s - $vgmt)
# end time to unix
# start time to seconds
:local inTime [:totime $1]
:local wPos [:find $inTime “w” -1]
:local dPos [:find $inTime “d” -1]
:local itLen [:find $inTime “.” -1] ; :if ([:typeof $itLen] = “nil”) do={:set itLen [:len $inTime]}
:local itSec [:pick $inTime ($itLen - 2) $itLen]
:local itMin [:pick $inTime ($itLen - 5) ($itLen - 3)]
:local itHou [:pick $inTime ($itLen - 8) ($itLen - 6)]
:local itDay 0
:local itWee 0
:if (([:typeof $wPos] = “nil”) and ([:typeof $dPos] = “num”)) do={:set itDay [:pick $inTime 0 $dPos] }
:if (([:typeof $wPos] = “num”) and ([:typeof $dPos] = “num”)) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = “num”) do={:set itWee [:pick $inTime 0 $wPos] }
:local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee))
# end time to seconds
# start (unix + future seconds) to time
:local ux ($Unix + $totitSec)
:local Fzerofill do={:return [:pick (100 + $1) 1 3]}
:local prMntDays [:toarray “0,0,31,59,90,120,151,181,212,243,273,304,334”]
:local vgmt [:tonum [/system clock get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
:local tzepoch ($ux + $vgmt)
:if ($tzepoch < 0) do={:set tzepoch 0} ; # unsupported negative unix epoch
:local yearStart (1970 + ($tzepoch / 31536000))
:local tmpbissex (($yearStart - 1968) / 4) ; :if ((($yearStart - 1968) % 4) = 0) do={:set ($prMntDays->1) -1 ; :set ($prMntDays->2) 30}
:local tmpsec ($tzepoch % 31536000)
:local tmpdays (($tmpsec / 86400) - $tmpbissex)
:if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={
:set tmpbissex ($tmpbissex - 1) ; :set ($prMntDays->1) 0 ; :set ($prMntDays->2) 31 ; :set tmpdays ($tmpdays + 1)
}
:if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1) ; :set tmpdays ($tmpdays + 365)}
:local mnthStart 12 ; :while (($prMntDays->$mnthStart) > $tmpdays) do={:set mnthStart ($mnthStart - 1)}
:local dayStart [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))]
:local timeStart (00:00:00 + [:totime ($tmpsec % 86400)])
:return “$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart”
}
[test@6.48.7] > :put [$futuredatetimestr 6d1h]
2025/06/01 18:32:09
(it’s 2025-05-26 17:32:09 on my country)

I’m using interval 1d00:00:00 and it’s not working

:local interval [/system scheduler get [find where name=TEST] interval]
:global futuredatetimestr do={
/system clock
:local vdate [get date]
:local vtime [get time]
:local vgmt [:tonum [get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:local prMntDays [:toarray “0,0,31,59,90,120,151,181,212,243,273,304,334”]
:local daysOnMnt [:toarray “0,31,28,31,30,31,30,31,31,30,31,30,31”]
:local LcaseMnts [:toarray “0,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local PcaseMnts [:toarray “0,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec”]
:local UcaseMnts [:toarray “0,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC”]
:local LcaseWeekDays [:toarray “thu,fri,sat,sun,mon,tue,wed”]
:local PcaseWeekDays [:toarray “Thu,Fri,Sat,Sun,Mon,Tue,Wed”]
:local UcaseWeekDays [:toarray “THU,FRI,SAT,SUN,MON,TUE,WED”]
:local NumbrWeekDays [:toarray “4,5,6,7,1,2,3”]
:local Fzerofill do={:return [:pick (100 + $1) 1 3]}
:local gmtSg “+”; :if ($vgmt < 0) do={:set gmtSg “-”; :set vgmt ($vgmt * -1)}
:local gmtHr [:pick [:totime $vgmt] 0 2]
:local gmtMn [:pick [:totime $vgmt] 3 5]
:local vdoff [:toarray “0,4,5,7,8,10”]
:local MM [:pick $vdate ($vdoff->2) ($vdoff->3)]
:local M [:tonum $MM]
:if ($vdate ~ “…/../…”) do={
:set vdoff [:toarray “7,11,1,3,4,6”]
:set M ([:find “xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC” [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
:if ($M>12) do={:set M ($M - 12)}
:set MM [:pick (100 + $M) 1 3]
}
:local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)]
:local Leap “No-Leap”
:if ((($yyyy - 1968) % 4) = 0) do={:set Leap “Leap”; :set ($prMntDays->1) -1; :set ($prMntDays->2) 30; :set ($daysOnMnt->2) 29}
:local mmm ($LcaseMnts->$M)
:local Mmm ($PcaseMnts->$M)
:local MMM ($UcaseMnts->$M)
:local MD ($daysOnMnt->$M)
:local dd [:pick $vdate ($vdoff->4) ($vdoff->5)]
:local d [:tonum $dd] ; :local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($prMntDays->$M) + ($d - 1))
:local YD (($prMntDays->$M) + $d)
:local www ($LcaseWeekDays->($totd % 7))
:local Www ($PcaseWeekDays->($totd % 7))
:local WWW ($UcaseWeekDays->($totd % 7))
:local WD ($NumbrWeekDays->($totd % 7))
:local HH [:pick $vtime 0 2]
:local H [:tonum $HH]
:local hh ([:tonum $HH] % 12); :if ($hh = 0) do={:set hh 12}; :set hh [$Fzerofill $hh]
:local h [:tonum $hh]
:local a “A”; :if ([:tonum $HH] > 11) do={:set a “P”}
:local aa “$a\4D”
:local mm [:pick $vtime 3 5]
:local m [:tonum $mm]
:local ss [:pick $vtime 6 8]
:local s [:tonum $ss]
:local Z “$gmtSg$gmtHr:$gmtMn”
:local Unix (((((($totd * 24) + $H) * 60) + $m) * 60) + $s - $vgmt)

end time to unix

start (unix + future seconds) to time

:local ux ($Unix + [:tonum $1])
:local Fzerofill do={:return [:pick (100 + $1) 1 3]}
:local prMntDays [:toarray “0,0,31,59,90,120,151,181,212,243,273,304,334”]
:local vgmt [:tonum [/system clock get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
:local tzepoch ($ux + $vgmt)
:if ($tzepoch < 0) do={:set tzepoch 0} ; # unsupported negative unix epoch
:local yearStart (1970 + ($tzepoch / 31536000))
:local tmpbissex (($yearStart - 1968) / 4) ; :if ((($yearStart - 1968) % 4) = 0) do={:set ($prMntDays->1) -1 ; :set ($prMntDays->2) 30}
:local tmpsec ($tzepoch % 31536000)
:local tmpdays (($tmpsec / 86400) - $tmpbissex)
:if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={
:set tmpbissex ($tmpbissex - 1) ; :set ($prMntDays->1) 0 ; :set ($prMntDays->2) 31 ; :set tmpdays ($tmpdays + 1)
}
:if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1) ; :set tmpdays ($tmpdays + 365)}
:local mnthStart 12 ; :while (($prMntDays->$mnthStart) > $tmpdays) do={:set mnthStart ($mnthStart - 1)}
:local dayStart [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))]
:local timeStart (00:00:00 + [:totime ($tmpsec % 86400)])
:return “$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart”
}

:put [$futuredatetimestr [:totime $interval]]

Is your copy&paste broken?
Is not the same script…

[test@6.48.7] > :put [$futuredatetimestr 1d00:00:00]
2025/05/27 18:47:04

Are you able to read and understand previous posts?
:local interval [/system scheduler get [find where name=TEST] interval]


and use

CODE

tag, not

QUOTE

tag, or make script ureadable

Thank you very much, my friend REX. These scripts are not easy at all, but how do I obtain the date and time separately?

Now it’s time for you to learn how to script, I can’t spoon-feed you.

Use :pick

remain the same

where are those going: pick

give me a hint please