Community discussions

MikroTik App
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

[SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 1:50 pm

Hello All,

I'm very embarassed with a little thing :
I'd like to compare the SMS timestamp to date time, but TimeStamp is formatted like that : May/23/2022 and system clock is like that : may/23/2022.
I'm looking for a simple way to make it case insensitive.
I'm running ros7.
Could you help me with that ? Thank you

Vincent
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 1:53 pm

If for hypothesys the date have same format on both, how you compare them?
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 2:03 pm

Hello Rextended,

I was thinking of putting the current date and timestamp in variables then comparing them. It is not possible ?

Regards,

Vincent
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 2:15 pm

I give you the soluction,
but first... paste this on terminal:
:global a "May/23/2022"
:global b "May/23/2022"
:if ($a <  $b) do={:put "$a <  $b"} else={:put "$a !<  $b"}
:if ($a <= $b) do={:put "$a <= $b"} else={:put "$a !<= $b"}
:if ($a =  $b) do={:put "$a =  $b"} else={:put "$a !=  $b"}
:if ($a >= $b) do={:put "$a >= $b"} else={:put "$a !>= $b"}
:if ($a >  $b) do={:put "$a >  $b"} else={:put "$a !>  $b"}
:if ($a != $b) do={:put "$a != $b"} else={:put "$a !!= $b"}
And see what is the problem....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive  [SOLVED]

Mon May 23, 2022 2:26 pm

search tag # rextended date2int engdate2int

convert the string (May|may|MAY)/23/2022 to number 20220523 (the "date" type on RouterOS do not exist)

:global engdate2int do={
    :local input    [:tostr $1]
    :local intYear  ([:tonum [:pick $input 7 11]] * 10000)
    :local M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $input 1 3] -1] / 2); :if ($M>12) do={:set M ($M - 12)}
    :set   M ($M * 100)
    :local intDay   [:tonum [:pick $input 4 6]]

    :return ($intYear + $M + $intDay)
}

You can test it with:
:put [$engdate2int "may/23/2022"]

:global a [$engdate2int "May/23/2022"]
:global b [$engdate2int "may/23/2022"]
:if ($a <  $b) do={:put "$a <  $b"} else={:put "$a !<  $b"}
:if ($a <= $b) do={:put "$a <= $b"} else={:put "$a !<= $b"}
:if ($a =  $b) do={:put "$a =  $b"} else={:put "$a !=  $b"}
:if ($a >= $b) do={:put "$a >= $b"} else={:put "$a !>= $b"}
:if ($a >  $b) do={:put "$a >  $b"} else={:put "$a !>  $b"}
:if ($a != $b) do={:put "$a != $b"} else={:put "$a !!= $b"}
Last edited by rextended on Wed May 10, 2023 11:18 pm, edited 3 times in total.
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 2:42 pm

Rextended,

Thank you so much for your help.
I even didn't know how to do a function for rOS.
I 'll study it and apply. I'm working on a script that ll send me a SMS when I' ll receive a warn from my provider.

Regards,

Vincent
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 2:44 pm

(And, I see, I can't compare strings)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 2:55 pm

Not quite exactly, you can just check if they are the same or different.
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 3:05 pm

Rextended,

I don't understand this line == :local intMonth ([:tonum ($arrMonths->[:pick $input 1 3])] * 100)
How does it works ?

Regards,

Vincent
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 3:19 pm

To be more precise, how does it $arrMonths find the correct value when $input 1 3 does not contains 3 characteres)

Vincent
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 4:09 pm

neither the array... (j|J)an=1 (f|F)eb=2 (m|M)ar=3... ;)
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 6:34 pm

Thank you for your help and patience.
As it seems to be impossible to get only the timestamp from /tool/sms/inbox and compare to current date, I ll find another way to send me a SMS from my provider when he warn me that I'm over quota.

Regards,
Vincent
Last edited by VincentL on Tue May 24, 2022 11:30 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 6:43 pm

The timestamp is like "May/23/2022 17:42:43 GMT -0"

Some examples:
:global engdate2int do={
    :local input    [:tostr $1]
    :local arrMonths {an=1;eb=2;ar=3;pr=4;ay=5;un=6;ul=7;ug=8;ep=9;ct=10;ov=11;ec=12}
    :local intYear  ([:tonum [:pick $input 7 11]] * 10000)
    :local intMonth ([:tonum ($arrMonths->[:pick $input 1 3])] * 100)
    :local intDay   [:tonum [:pick $input 4 6]]

    :return ($intYear + $intMonth + $intDay)
}

{
:local timestamp "May/23/2022 17:42:43 GMT -0"
:local today [/sys clock get date]

:local intstamp [$engdate2int $timestamp]
:local inttoday [$engdate2int $today]

:put "today = $inttoday ; timestamp = $intstamp"

:if ( $inttoday      = $intstamp) do={ :put "SMS Sent today" }
:if (($inttoday - 1) = $intstamp) do={ :put "SMS Sent yesterday" }
}


{
:local searchtoday [:pick [/sys clock get date] 1 11]
/tool sms inbox
:foreach sms in=[find where timestamp~$searchtoday] do={
    :put "timestamp=$[get $sms timestamp] phone=$[get $sms phone] type=$[get $sms type] message=$[get $sms message]"
}
}
 
VincentL
newbie
Topic Author
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: [SMS] Timestamp, system date and case sensitive

Mon May 23, 2022 8:38 pm

@rextended,

It's just awesome !
I have a lot to learn, especially doing thing more simple.
I've read, understood and used both of your examples, and finally, the second fit perfectly to my needs.

For other people that fall in this thread :
:local phoneNumber "+XXyourPhoneNumber"
:local inMessage "SMS template to search"
:local outMessage "Quota Exceeded"
:local today [:pick [/sys clock get date] 1 11]
 /tool sms inbox
 : foreach sms in=[find where timestamp~$today and message~$inMessage] do={
  /tool/sms/send message=$outMessage phone-number=$phoneNumber lte1
  }
XX is your local country indicative

Thank a lot again, it's great !

Vincent

Who is online

Users browsing this forum: Cmon169, Google [Bot] and 14 guests