Community discussions

MUM Europe 2020
just joined
Topic Author
Posts: 3
Joined: Thu Aug 08, 2013 4:53 pm

Convert String to Time value

Mon Aug 12, 2013 12:05 pm


I need to convert a string to time.

I have a string like "jan/23/2013 10:25:11" and my script schould read this as a time value.

I need this to compare with an other date like:
:if ($date1 < $date2) do={....}
My idea was to convert with :totime but that didn't work.

Have someone an tip for me?!


I use RouterOS 6.1

Sorry for my english..........
Posts: 471
Joined: Sat May 06, 2006 4:11 pm

Re: Convert String to Time value

Mon Aug 12, 2013 4:37 pm

I do not know if the ROS have sub-string manipulation capabilities, but if there is no standard function to convert that string to time (I wonder, what is the format of :totime function?) then you have to seek that route. Note: Speed impact to your running system will be awful and I hope you need not run that very often.
User avatar
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Convert String to Time value

Mon Aug 12, 2013 5:55 pm

(I wonder, what is the format of :totime function?)
":totime" merely converts types. You need to have either a number or a string, which can be interpreted into a "time" type.

The problem is that the "time" type is not relative to any COMMON point in time. In other words, "10:00:00", according to the "time" type is "10 hours after some undefined point in time", not "10 hours since today's 00:00" (as is the case with the clock) or "10 hours since 1st January 1970" (as is the case with timestamps).

As it so happens, there's been a recent topic in the forum that might help. Convert both dates to timestamps, and compare the timestamps.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: No registered users and 9 guests