Script for Date and Time

Hi,guys

Is there any way to get Date (today) from MT? Like function date() in the PHP.

thx

:put [/system clock get date]

or

:local datetime [/system clock get date]

Sam

how about I just get the date and the month. Can mikrotik script be like that? so variable date = 2 variable month = 2

thx

thank you, I remember the pick command, I think I just use the pick command. ^^

yes, the pick command will ‘pick out’ sections based on a delimeter.

Sam

and other day and month and year

:local fecha [/system clock get date]
:local dia [ :pick $fecha 4 6 ]
:local mes [ :pick $fecha 0 3 ]
:local year [ :pick $fecha 7 11 ]
:log info “date format : $dia $mes $year”
:local archivo “/myfile_$year_$mes_$dia.txt”
etc

:local date
:local time
:local day
:local month
:local year
:local hour

:set date [/system clock get date]
:set time [/system clock get time]
:set day [:pick $date 4 6]
:set hour [:pick $time 0 2]

haha thank you m8 you saved my day with this little trick

how to operate the date?
for example :
date + num of day
feb/01/2017 + 2
will return
feb/03/2017
i have try this command but still failed
:put ([/system clock get date] + 2d)

please help.

ROS scripting has ridiculous support for dates.
You can’t add/substract them.
You need split you date on days, months, years and then do date arithmetic taking into consideration days in the months and leap years.
From one hand it is no difficult task for programmers, but admins usually not programmers %)

Not exact answer to you question but also about dates:
http://forum.mikrotik.com/t/calculate-the-difference-between-two-dates/107120/1

In you case task is easier (comparing to get difference between dates).

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

great solution, thank you so much. you save my time.

thank you for this valuable lesson