All times are UTC + 5:30 hours




Post new topic Reply to topic  [ 3 posts ] 
  Print view

Syntax for date comparison
Author Message
PostPosted: Thu Aug 09, 2012 8:57 pm 
Registered User
Offline

Joined: Thu Feb 09, 2012 3:46 pm
Posts: 158
I was trying to compare two dates as follows (and with a few minor variants):
Code:
<cms:if "<cms:date k_page_date format='Y-m-d' />" ge "<cms:date format='Y-m-d' />" >

with no success, so ended up using this:
Code:
<cms:set compare_today="<cms:date format='Y-m-d'/>" />
<cms:set compare_event_date="<cms:date k_page_date format='Y-m-d' />" />
<cms:if compare_event_date ge compare_today >

which works OK.

It would seem preferable to do this in a single line of code if possible ... or isn't it?


Top
 Profile  
 

Re: Syntax for date comparison
PostPosted: Fri Aug 10, 2012 3:57 am 
Moderator
Offline

Joined: Wed Dec 01, 2010 5:35 pm
Posts: 1395
Hi Potato,

The behaviour you observed has to do with the way language parsers are constructed.
To put it in simple terms, the LHS (Left Hand Side) of an expression has to be a variable.
The RHS (Right Hand Side) may be a variable or a constant or another expression.

With that understood, you can see that you were supplying an expression as the LHS of your statement
Quote:
<cms:if "<cms:date k_page_date format='Y-m-d' />" ge "<cms:date format='Y-m-d' />" >

The right way could be first placing the result of the expression into a variable and then using it as LHS:
Code:
<cms:set compare_event_date="<cms:date k_page_date format='Y-m-d' />" />
<cms:if compare_event_date ge "<cms:date format='Y-m-d' />" >
   ...
</cms:if>

Sorry for all that developer-parlance :)
Hope this helps.


Top
 Profile  
 

Re: Syntax for date comparison
PostPosted: Fri Aug 10, 2012 2:57 pm 
Registered User
Offline

Joined: Thu Feb 09, 2012 3:46 pm
Posts: 158
thanks KK - crystal clear! (were you ever a teacher? you have a gift for explaining things!)


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 5:30 hours


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© 2001-2010 SYS-Solutions All Rights Reserved