Есть такие скриптики
func_date2days - count days from base to given date.
########## func_date2days - count days from base to given date.
# Input: two dates like "jan/1/2017"
########## uncomment for testing
:local date $1
#:local date "sep/13/2017"
#:put $date
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
: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}
#date
:local dd [:tonum [:pick $date 4 6]]
:local yy [:tonum [:pick $date 7 11]]
:local mm [:pick $date 0 3]
:set mm ($months->$mm)
#0. We have dd/mm/yy
:local res 0
#1. Move to 01/mm/yy
:set res ($res+$dd-1)
#2. Move to 01/01/yy
:while ($mm>1) do={
:set mm ($mm-1)
:local dm [:pick $mdays ($mm-1)]
:if ($mm=2 && (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }
:set res ($res+$dm)
}
#3. Move to 01/01/1900
:while ($yy>$base) do={
:set yy ($yy-1)
:set res ($res+365)
:if ( ( ($yy&3=0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set res ($res+1)
}
}
:return $res
func_days2date - convert days from base to date string
########## func_days2date - convert days from base to date string
# Input: days like 18762 (may/15/2021)
########## uncomment for testing
:local days $1
#:local days 789
#:put $days
#days starts from 1
:set days ($days + 1)
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {1="jan";2="feb";3="mar";4="apr";5="may";6="jun";7="jul";8="aug";9="sep";10="oct";11="nov";12="dec"}
#date
:local yy $base
:local mm 0
# base year is not leap
:local daydiff 365
:local isleap false
#1. Move to 01/01/yy
:while ($days > $daydiff) do={
:set days ($days - $daydiff)
:set yy ($yy + 1)
:if ( ( ($yy & 3 = 0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set daydiff 366
:set isleap true
# :put "adjust: $yy, days: $days"
} else={
:set daydiff 365
:set isleap false
}
# :put "yy: $yy, days: $days"
}
#2. Adjust feb 29 if leap year
#:put "mmm: $mm, days: $days, isleap: $isleap"
:if ($isleap) do={
# :put "adjust month days"
:set ($mdays->1) 29
}
#3. Move to 01/mm/yy
:while ($days > $mdays->$mm) do={
# :put ($mdays->$mm)
:set days ($days-($mdays->$mm))
:set mm ($mm + 1)
# :put "mm: $mm, days: $days"
}
:local month [:tostr ($mm + 1)]
:set month ($months->$month)
:if ($days < 10) do={ :set days ("0".(:tostr $days)) } else={ :set days (:tostr $days) }
:local res "$month/$days/$yy"
#:put $res
:return $res
Первый где-то наковырял, второй понадобился, сам нарисовал :)
Можно совместить и использовать
:local date2days [:parse [/system script get func_date2days source]]; :local today "may/12/2023"; :local days [$date2days $today]; :put $days;
:local days2date [:parse [/system script get func_days2date source]]; :put [$days2date ($days-1)]