RE: unlang time / date comparison
Thanks Arran, I'll give it a try. I did find something to do with %1 / %I (can't remember which) and dividing by "epoch" so may be able to use that too? If in doubt give it a go eh? Thanks Andy -----Original Message----- From: freeradius-users-bounces+andy.franks=sath.nhs.uk@lists.freeradius.org [mailto:freeradius-users-bounces+andy.franks=sath.nhs.uk@lists.freeradiu s.org] On Behalf Of Arran Cudbard-Bell Sent: 18 September 2012 23:05 To: FreeRadius users mailing list Subject: Re: unlang time / date comparison On 18 Sep 2012, at 22:38, "Franks Andy \(RLZ\) IT Systems Engineer" <Andy.Franks@sath.nhs.uk> wrote:
Hi,
Hopefully a simple question. I've looked around for a while but can't find the answer to this.
I'd like to be able to take a date/time from a sql database, use unlang (not a module) to compare it to the current time and make a decision based on the fact that it's, for example, less or more than 3600 seconds/60 minutes/1 hour etc ago.
Use one of the SQL functions (UNIX_TIMESTAMP()) to pull the date field value out as an integer and do a straight comparison with "%{l}". Or if you write a SQL timestamp string into a date type attribute, it might be smart enough to parse it for you, and then you can do "%{integer:Timestamp-Attr}" and compare with "%{l}". Not 100% sure the code is there to do that though... -Arran - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On 19 Sep 2012, at 08:50, Franks Andy (RLZ) IT Systems Engineer <Andy.Franks@sath.nhs.uk> wrote:
Thanks Arran, I'll give it a try. I did find something to do with %1 / %I (can't remember which)
%1expands to the first regexp match, %l should expand to a UNIX timestamp. You'll be looking for something like: if ("%{sql:SELECT UNIX_TIMESTAMP(<my field>) FROM <my table> WHERE 1}" < "%{l}") { } FR will always try and do the right thing when it comes to comparing string values, and will automatically call atoi for you, and perform integer comparisons, but i'm not sure with a string to integer comparison, it'll try and parse the string as a date, hence suggesting you make it easier for the server by pulling it out as an integer. What'd be neat is if the one letter expansions were converted to actual attributes, then we could use their type as a hint as to how the comparison should be performed. -Arran
participants (2)
-
Arran Cudbard-Bell -
Franks Andy (RLZ) IT Systems Engineer