Greetings to all and Happy Labor Day, there is the possibility that with a script you can convert the UPTIME of a routerboard in the time and date of for example this:
1w 3d 13:42:38.
EL DONCITO.
Greetings to all and Happy Labor Day, there is the possibility that with a script you can convert the UPTIME of a routerboard in the time and date of for example this:
1w 3d 13:42:38.
EL DONCITO.
Convert this:
:put [/system/resource/get uptime]
5w4d12:38:02
to what?
Thanks for answering JOTNE, convert 5w3d13:35:38 in the time and date the routerboard was rebooted.
EL DONCITO.
Is extremly tedious to do that, on mikrotik “datetime” do not exist and is not possible to simply subtract from current “datetime” the uptime value.
Also, with subsequent subtraction, is not impossible, but overcomplicated because you must count how many days are in one month, if have Feb29 or not, etc.
You have a craze for these uptime and startup time.
search tags # rextended online uptime start date time
Work correctly only if RouterBOARD time is syncronized.
(compatible also with new date format on RouterOS 7.10+)
:global currdatetimestr 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 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 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}
:local mmm ($LcaseMnts->$M)
:local Mmm ($PcaseMnts->$M)
:local MMM ($UcaseMnts->$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 www ($LcaseWeekDays->($totd % 7))
:local Www ($PcaseWeekDays->($totd % 7))
:local WWW ($UcaseWeekDays->($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)
# :return "$yyyy-$MM-$dd\54$HH:$mm:$ss$Z $Www $Leap $Unix"
:return $Unix
}
: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"
}
:global timetoseconds 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 - 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))
:return $totitSec
}
:put "RouterBOARD is started $[$unixtodatetime ([$currdatetimestr] - [$timetoseconds [/system resource get uptime]])]"
Grateful for your help friend Rextended, and sorry for so much trouble but the date instead of being in the YY-MM-DD format, you could change it to DD-MM-YY.
RouterBOARD is started 2022-05-02 12:36:45RouterBOARD is started 02-05-2022 12:36:45.
You have already all the other scripts maded for you, apply the other scripts to the $datetimeStart at the end.
Is time you study and try for yourself… ![]()
REX friend don’t be selfish with me, tell me how I can change.
And I don’t bother you anymore for now.
2022-05-02
02-05-2022
EL DONCITO
Selfish? After all the scripts I made for you? What ungrateful… ![]()
Help me please friend REX
This is my last question for now.
EL DONCITO.
You never bother me when you ask for something new and interesting…
Ok, wait some minutes… ![]()
For you…
Special Venezuelan version for El Doncito:
:global currdatetimestr 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 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 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}
:local mmm ($LcaseMnts->$M)
:local Mmm ($PcaseMnts->$M)
:local MMM ($UcaseMnts->$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 www ($LcaseWeekDays->($totd % 7))
:local Www ($PcaseWeekDays->($totd % 7))
:local WWW ($UcaseWeekDays->($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)
# :return "$yyyy-$MM-$dd\54$HH:$mm:$ss$Z $Www $Leap $Unix"
:return $Unix
}
: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"
:return "$[$Fzerofill $dayStart]/$[$Fzerofill $mnthStart]/$yearStart $timeStart"
}
:global timetoseconds 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 - 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))
:return $totitSec
}
:put "RouterBOARD is started $[$unixtodatetime ([$currdatetimestr] - [$timetoseconds [/system resource get uptime]])]"
The “International ISO Version” is here:
https://forum.mikrotik.com/viewtopic.php?p=930833#p930465
Thank you very much friend REX as we say here in my country, Thank you my “PANA”.
EL DONCITO.
take a closer look: expecting you, I’ve already done it.. even with the Venezuelan months… ![]()
Eres mi “PANA” REX.
EL DONCITO.
Grazie…
REX friend, why does this appear when I execute the script in the console?
failure: connection timeout
Try to open the page used for the service:
https://helloacm.com/
Is not mine, if do not work, you must wait than it come back.
OK, and tell me one last thing, should I set the script to start when the ROUTERBOARD starts?
EL DONCITO.
yes, but first put a delay until internet is not available
:delay 120s