EE Insider Tips
Sponsored by EE Screencasts
ExpressionEngine mini-howtos created by the EE Insider community.
More precise date comparisons
As with most EE variables, you can do comparisons on date variables, like so:
{if date_variable == "foo"}
Do something
{/if}
However, if you need more precise date comparisons, you can do something like this:
{if "{date_variable format='%m/%d/%Y'}" == "01/01/2009"}
Do something
{/if}
You can also use this to compare two date variables (for example, comparing a start and end date for an event):
{if "{start_date format='%m%d%Y'}" == "{end_date format='%m%d%Y'}"}
{start_date format="%F %j, %Y"}
{if:else}
{start_date format="%F %j"}-{end_date format="%j, %Y"}
{/if}
I recently used this on a project, and it came in very handy.
Email
Print
Post to Twitter
Post to Delicious
Add Your Comment?
You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.
Sign up now (or login).