Community discussions

MikroTik App
 
bc4n
newbie
Topic Author
Posts: 30
Joined: Wed Jul 26, 2006 4:05 am
Location: Indonesia

Script for Date and Time

Thu Feb 01, 2007 2:49 am

Hi,guys

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

thx
 
changeip
Forum Guru
Forum Guru
Posts: 3833
Joined: Fri May 28, 2004 5:22 pm

Thu Feb 01, 2007 6:24 pm

:put [/system clock get date]

or

:local datetime [/system clock get date]

Sam
 
bc4n
newbie
Topic Author
Posts: 30
Joined: Wed Jul 26, 2006 4:05 am
Location: Indonesia

Fri Feb 02, 2007 5:34 am

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

thx
 
bc4n
newbie
Topic Author
Posts: 30
Joined: Wed Jul 26, 2006 4:05 am
Location: Indonesia

Fri Feb 02, 2007 5:36 am

thank you, I remember the pick command, I think I just use the pick command. ^^
 
changeip
Forum Guru
Forum Guru
Posts: 3833
Joined: Fri May 28, 2004 5:22 pm

Sun Feb 04, 2007 8:31 pm

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

Sam
 
wencs
just joined
Posts: 10
Joined: Wed Mar 26, 2014 7:14 pm

Re:

Wed May 14, 2014 12:21 pm

:put [/system clock get date]

or

:local datetime [/system clock get date]

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
 
wcsnet
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Mon Apr 29, 2013 12:43 pm
Location: South Africa

Re: Script for Date and Time

Wed Jul 30, 2014 11:23 am

: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]
 
User avatar
spippan
Member
Member
Posts: 478
Joined: Wed Nov 12, 2014 1:00 pm

Re: Re:

Wed Jul 12, 2017 12:31 pm

:put [/system clock get date]

or

:local datetime [/system clock get date]

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
haha thank you m8 you saved my day with this little trick
 
User avatar
amitkw
just joined
Posts: 13
Joined: Fri Jun 30, 2017 3:38 am
Location: Indonesia
Contact:

Re: Script for Date and Time

Thu Oct 26, 2017 2:53 pm

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.
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 175
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: Script for Date and Time

Thu Oct 26, 2017 4:16 pm

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:
viewtopic.php?t=119703

In you case task is easier (comparing to get difference between dates).
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 175
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: Script for Date and Time

Fri Oct 27, 2017 5:22 pm

 
User avatar
amitkw
just joined
Posts: 13
Joined: Fri Jun 30, 2017 3:38 am
Location: Indonesia
Contact:

Re: Script for Date and Time

Sat Oct 28, 2017 3:48 am

great solution, thank you so much. you save my time.
 
User avatar
amitkw
just joined
Posts: 13
Joined: Fri Jun 30, 2017 3:38 am
Location: Indonesia
Contact:

Re: Script for Date and Time

Sat Oct 28, 2017 3:50 am

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:
viewtopic.php?t=119703

In you case task is easier (comparing to get difference between dates).
thank you for this valuable lesson