All complicated steps useless, isn't it better to use :timestamp and relative functions on RouterOS v7???
For v6 there are still my functions to get the exact date going from unix time.
viewtopic.php?p=977170#p977170
(changed / to - on function)termial code
[rex@7.16.2v7] > :global unixtodatetime do={{... :local ux [: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"{... }[rex@7.16.2v7] > :put [$unixtodatetime ([:totime "2025-03-26 23:45:00"] - [:tonum [/system clock get gmt-offset]] + 30m)] ; # on manual, subtract timezone2025-03-27 00:15:00[rex@7.16.2v7] > :put [$unixtodatetime ([:timestamp] + 30m)] ; # timezone and timestamp readed from RouterOS local UTC clock2025-03-26 18:30:18at this point is easy to split "2025-03-26 18:30:18" on date and time for scheduler.
or with a little mod:terminal code
[...]{... :return ("$yearStart-$[$Fzerofill $mnthStart]-$[$Fzerofill $dayStart]","$timeStart")[...][rex@7.16.2v7] > :local nstart [$unixtodatetime ([:timestamp] + 30m)] ; :put "Start date: $($nstart->0) and start time: $($nstart->1)" Start date: 2025-03-26 and start time: 18:30:18you have one array with on ->0 the date, and on ->1 the time, already ready for use to create the scheduler.
The variable “nstart” is not an array and the example does not work:
Code:
[admin@MikroTik] > :local nstart [$unixtodatetime ([:timestamp] + 30m)] ; :put "Start date: $($nstart->0) and start time: $($nstart->1)"Start date: and start time:[admin@MikroTik] > :local nstart [$unixtodatetime ([:timestamp] + 30m)]; :put [:typeof $nstart]str
Statistics: Posted by diamuxin — Sun Apr 06, 2025 1:53 pm