⚠️WARNING: RouterOS v7.10+ will break all scripts based on [/system clock get date] or other date(s)

Back in 2018 it “was considered” to add a function library for scripting, and input was requested for what functions would be useful to have: http://forum.mikrotik.com/t/built-in-function-library/117288/114
One of the first proposed category was manipulation of date/time values.

Unfortunately we never got that function library. If it had been implemented, the autodetection and handling of the new date format could just be added there, and all user scripts would automatically adapt to the new situation…
(or their programmer would be kicked for not using standard functions from the library)

Come on, it took me a moment to modify all my scripts on the forum and in production to be ready
for the 9 September for the long-term v7.23.5 where finally we can have the ISO time for Zero Trust on BFG (:P)…
http://forum.mikrotik.com/t/routeros-v6-maintenance-mode/160861/1

I have a cat biscuit for you! :slight_smile: (showoff)

I think the issue is not how much work it is for a capable programmer to modify the code, but more the vast number of copy/paste programmers that have tinkered a script that works and suddenly it breaks when upgrading. It may even take quite some time before that is noticed at all, e.g. when the script has some monitoring/alerting purpose.
In case some company has deployed hundreds of routers with some script, and did not think about an automated way for maintenance, it may be a big headache to fix.

But in general I agree that the number of scripts that parses a date field (rather than simply reading it and using it in some message) is probably quite small.
I have done some scripting but I never parsed the field, only copied it to a variable for later compare.

You always manage to give me that point of view that I miss,
Thank you.

it’s also easy to update one or two devices, when you’ve got scripts baked into default setup scripts installed on thousands of devices spread all over the country, it’s a little more challenging to update. Thankfully this particular change does not affect any of our deployed scripts, only how we parse some data server side that gets retrieved from the API, so it’s an easy fix for us, but just because it’s an easy fix for us doesn’t mean MikroTik should get a free pass and break functionality for anyone who does have deployed scripts that might be affected by this. They absolutely should handle this change such that it does not become a new default setting when upgrading existing devices, and retain the old format as an option.

I hope the update process is not automatic (and neither is installing beta in production).
It is extremely easy, when you update the software, also update the scripts onboard of the machine…
And then, if years ago you had foreseen the self-updating of the onboard scripts… there’s nothing to worry about…

Fix for oxydize:
http://forum.mikrotik.com/t/v7-10beta-testing-is-released/166567/171

Looks like the situation is unchanged in 7.10beta7… Or I did not find the switch.

Concur and as I wrote in another post:

I want to emphasize that we welcome the new date format. HOWEVER, implementing it in a way that breaks compatibility, and in addition absolutely unnecessarily, is just plain stupidity.

And of course, you can “fix” the problem with various modifications, but the level of effort required varies depending on its occurrence. These type of changes is bound to have serious ramifications but the magnitude remains to be seen. People who don’t understand the implications of this issue shouldn’t comment on the matter IMO.

@rextended

Would you revive this for me, please? It doesn’t work correctly anymore.

:local 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"}
:local today [/system clock get date]
:local dateinside "$[:pick $today 7 11]-$($arrMonths->[:pick $today 1 3])-$[:pick $today 4 6]"
:local backupfile "$[/system identity get name]_$dateinside_$[/system clock get time]_$[/system resource get uptime].backup"

2023-06-16_21-14-57.jpg

This work regardless the RouterOS date format
:local isodateonly do={
/system clock
:local vdate [get date]
: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)]
:return “$yyyy-$MM-$dd”
}

:local backupfile “$[/system identity get name]$[$isodateonly]$[/system clock get time]_$[/system resource get uptime].backup”

***********_2023-06-16_21:34:39_1w6d12:05:54.backup

Thank you very much.

I have a similar problem. You load the returned date into a var then it appears I could only pick from position 0. After a bit of testing the pick function seems to have changed from the documentation. The syntax now appears to be :pick []. To get my scripts to work I have changed the values in the pick function.

:global fetchdate [/system clock get date]
[root@main-router] > :put $fetchdate
2023-06-17
[root@main-router] > :put [:pick [/system clock get date] 0 4]
2023
[root@main-router] > :put [:pick [/system clock get date] 5 7]
06
[root@main-router] > :put [:pick [/system clock get date] 8 10]
17

@AUsquirrel, Thank you.

i was able to get yesterday date using following script.but recent updates killed it. Can anyone fix this for me

func_date

################################################################### func_shiftDate - add days to date
#  Input: date, days
#    date - "jan/1/2017"
#    days - number, +/-
################################################################### uncomment for testing
#:local date "jan/01/2100"
#:local days 2560
########################################
#:put "$date + $days"
#use external functions
:local mdays  {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {"jan"=1;"feb"=2;"mar"=3;"apr"=4;"may"=5;"jun"=6;"jul"=7;"aug"=8;"sep"=9;"oct"=10;"nov"=11;"dec"=12}
:local monthr  {"jan";"feb";"mar";"apr";"may";"jun";"jul";"aug";"sep";"oct";"nov";"dec"}

:local dd  [:tonum [:pick $date 4 6]]
:local yy [:tonum [:pick $date 7 11]]
:local month [:pick $date 0 3]

:local mm ($months->$month)
:set dd ($dd+$days)
#:put $dd

:local dm [:pick $mdays ($mm-1)]
:if ($mm=2 && (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }

:while ($dd>$dm) do={
  :set dd ($dd-$dm)
  :set mm ($mm+1)
  :if ($mm>12) do={
    :set mm 1
    :set yy ($yy+1)
  }
 :set dm [:pick $mdays ($mm-1)]
 :if ($mm=2 &&  (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }
};

:while ($dd<=0) do={
 :set mm ($mm-1)
  :if ($mm=0) do={
    :set mm 12
    :set yy ($yy-1)
  }
 :set dm [:pick $mdays ($mm-1)]
 :if ($mm=2 &&  (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }
 :set dd ($dd+$dm)
};

:local res "$[:pick $monthr ($mm-1)]/"
:if ($dd<10) do={ :set res ($res."0") }
:set $res "$res$dd/$yy"
:return $res



#############################################################################
# Get Yesterday
#######################################################################





:local shiftDate [:parse [/system script get func_date source]]
:local DT ([/system clock get date])
:local LASTDAY [$shiftDate date=$DT days=-1]
:put "TODAY Date = $DT"
:put "YESTERDAY date = $LASTDAY"


###################### Month /  Year #################



:local arrMonths {jan="January";feb="February";mar="March";apr="April";may="May";jun="June";jul="July";aug="August";sep="September";oct="October";nov="November";dec="December"}
:local strYear [:pick $LASTDAY 7 11]
:local strMonth ($arrMonths->[ :pick $LASTDAY 0 3 ])
:local strDay [:pick $LASTDAY 4 6]

source - https://aacable.wordpress.com/tag/mikrotik-datetime/

as @pe1chl wrote…

if you don’t mind, can you review above code & fix it for me. please @rextended

http://forum.mikrotik.com/t/script-to-calculate-next-date/113437/1

Thanks i removed all previous code & moved to your one. works very well. Thank you again