Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Can it be done with a script?

Thu Apr 07, 2022 9:33 pm

Greetings, friends, you can change the time of the format that the routerboard brings from 24 hours, to (AM-PM), according to the following example:

08:05:00 08:05:00 AM.
15:18:00 03:18:00 PM.

Thanks for your help.



EL DONCITO.
 
holvoetn
Forum Guru
Forum Guru
Posts: 5422
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Can it be done with a script?

Thu Apr 07, 2022 9:53 pm

Pseudo code:
If value(<first two digits) > 12
then
newvalue=value(<first two digits>) - 12
print new value and all the rest
print PM
else
print value as it was
print AM
endif

Start your engines ...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Can it be done with a script?

Thu Apr 07, 2022 10:07 pm

You, as usual, do not describe entirely the request.
Where that time must be read?
Where that time must be print?

The RouterOS can not be "nationalized".
Dummy date format and 24h clock.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Can it be done with a script?

Thu Apr 07, 2022 10:14 pm

Pseudo code:
If value(<first two digits) > 12
then
newvalue=value(<first two digits>) - 12
print new value and all the rest
print PM
else
print value as it was
print AM
endif

Start your engines ...
24 do not exist, everytime you have from 00 to 23
00 = 12 AM
01 = 01 AM
...
11 = 11 AM
12 = 12 PM
13 = 01 PM
14 = 02 PM
...
22 = 10 PM
23 = 11 PM
 
holvoetn
Forum Guru
Forum Guru
Posts: 5422
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Can it be done with a script?

Thu Apr 07, 2022 10:22 pm

Ah yes, lookup table, that's also an option :D
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Can it be done with a script?

Thu Apr 07, 2022 10:52 pm

This is the "easy" part...

example code

:for i from=0 to=23 step=1 do={
    :local hours  $i
    :local mhours [:tonum $hours]
    :local msymbl "AM"
    :if ($mhours > 11) do={:set msymbl "PM"}
    :set mhours ($mhours % 12)
    :if ($mhours = 0) do={:set mhours 12}
    :if ($mhours < 10) do={:set mhours "0$mhours"}
    :local mtime "$mhours $msymbl"
    :local test $i
    :if ($test < 10) do={:set test "0$test"}
    :put "$test = $mtime"
}
Just for start...
Last edited by rextended on Thu Apr 07, 2022 11:17 pm, edited 3 times in total.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Can it be done with a script?

Thu Apr 07, 2022 10:53 pm

It is to register it in a script but with AM-PM time




EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Can it be done with a script?  [SOLVED]

Thu Apr 07, 2022 11:07 pm

international to meridian code

{
    :local itime  [/system clock get time]
    :local hours  [:pick $itime 0 2]
    :local minsec [:pick $itime 2 8]
    :local mhours [:tonum $hours]
    :local msymbl "AM"
    :if ($mhours > 11) do={:set msymbl "PM"}
    :set mhours ($mhours % 12)
    :if ($mhours = 0) do={:set mhours 12}
    :if ($mhours < 10) do={:set mhours "0$mhours"}
    :local mtime "$mhours$minsec $msymbl"

    :put "$itime = $mtime"
}
22:07:27 = 10:07:27 PM
 
holvoetn
Forum Guru
Forum Guru
Posts: 5422
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Can it be done with a script?

Thu Apr 07, 2022 11:54 pm

It is to register it in a script but with AM-PM time
Why ? Whatever you do with it afterwards, it's in my view mostly better to use 24h format.
Always sorts nicely.
Always can be evaluated.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Can it be done with a script?

Fri Apr 08, 2022 4:13 pm

Thank you friend rextended.




EL DONCITO.

Who is online

Users browsing this forum: No registered users and 8 guests