Community discussions

MikroTik App
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

how to get GMT Offset in command?

Mon Aug 28, 2017 10:00 am

wanted to know if there is a way to get the GMT as shown in the winbox?
because if mt gmt-oofset is +3 and I use this command:
:put ([/system clock get gmt-offset ]/3600
the resault is : 3
but if my gmt-offset is -3
the resault is : 1193043

so what can I do?


Thanks ,
 
pe1chl
Forum Guru
Forum Guru
Posts: 10234
Joined: Mon Jun 08, 2015 12:09 pm

Re: how to get GMT Offset in command?

Mon Aug 28, 2017 10:39 am

Try not dividing it by 3600
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: how to get GMT Offset in command?

Mon Aug 28, 2017 11:52 am

but what to do if I need to create a 1 command for all my routers
and some of then are in +3 and some on -3?

is there no other way?

Thanks ,
 
pe1chl
Forum Guru
Forum Guru
Posts: 10234
Joined: Mon Jun 08, 2015 12:09 pm

Re: how to get GMT Offset in command?

Mon Aug 28, 2017 11:54 am

Did you try not dividing it by 3600?
What is the result when you do that?
 
User avatar
strods
MikroTik Support
MikroTik Support
Posts: 1625
Joined: Wed Jul 16, 2014 7:22 am
Location: Riga, Latvia

Re: how to get GMT Offset in command?

Tue Aug 29, 2017 4:44 pm

This is not the best way how to do this, but I managed to use this:
:put [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)]

For example, if you try this :put [:totime ([/system clock get gmt-offset ]] and get some strange value, then try this :put [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)].
 
User avatar
strods
MikroTik Support
MikroTik Support
Posts: 1625
Joined: Wed Jul 16, 2014 7:22 am
Location: Riga, Latvia

Re: how to get GMT Offset in command?  [SOLVED]

Tue Aug 29, 2017 4:47 pm

Example:
{
:local t [:totime [/system clock get gmt-offset ]]
if ( [:len $t] != 8 ) do={
:set $t [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)]
}
:put $t
}
 
pe1chl
Forum Guru
Forum Guru
Posts: 10234
Joined: Mon Jun 08, 2015 12:09 pm

Re: how to get GMT Offset in command?

Tue Aug 29, 2017 6:02 pm

It looks like a signed/unsigned problem. Is the value of the timezone offset incorrectly returned as unsigned, or is the division operator incorrectly treating it as unsigned?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: how to get GMT Offset in command?

Tue Aug 29, 2017 6:21 pm

From a quick test, I'm seeing that the gmt-offset itself is returned as unsigned (or more accurately, as a "num" value).

Technically, RouterOS does not have a signed integer type. The "num" type values are 64 bit unsigned integers. "time" values however can be negative. IMHO, that's the type this should be returned as in general. The fix strods provided does just that - convert the "signed" 64 bit integer into a time value that is negative if necessary.
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: how to get GMT Offset in command?

Wed Aug 30, 2017 11:40 am

Thanks ,
 
ndbjorne
just joined
Posts: 23
Joined: Sat Dec 15, 2012 5:06 pm
Location: Italy

Re: how to get GMT Offset in command?

Fri Dec 23, 2022 9:05 pm

Alternative
{
:local tZone [/system clock get gmt-offset];
:local tzHour;
:local tzMin;
:if ([:tonum $tZone] > 43200) do={
    :set tZone    [:totime ($tZone - (2147483647 * 2) - 2)];
    :set tzHour   [:pick $tZone 0 3];
    :set tzMin    [:pick $tZone 4 6];
} else={
    :set tZone    [:totime $tZone];
    :set tzHour   ("+".[:pick $tZone 0 2]);
    :set tzMin    [:pick $tZone 3 5];
}
:put ($tzHour.$tzMin);
}
Thanks strods
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12003
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how to get GMT Offset in command?

Sat Dec 24, 2022 10:43 am

43200: Wrong value, time zones +12:45 (New Zealand), +13:00 (New Zealand, Samoa and Tonga) and +14:00 exist (Kiribati).
Do not cost nothing use at least 24 hours...

(2147483647 * 2) - 2: why not directly subtract 4294967296 (0x100000000)???

Usually Time Zone is writed with : like +01:00, not +0100


"Nice", short and formatted.
{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:local tzstr  [:pick "$tzsign$[:totime $tzmin]" 0 6]
:put "Time Zone offset on this routerboard is $tzstr ($tzsign$tzmin seconds)"
}


Just the offset string
{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:local tzstr  [:pick "$tzsign$[:totime $tzmin]" 0 6]
:put "Time Zone offset on this routerboard is $tzstr"
}


Just the value on minutes:
{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:put "Time Zone offset on this routerboard is $tzsign$tzmin seconds"
}

Who is online

Users browsing this forum: d513, Majestic-12 [Bot] and 110 guests