1

I'm using some php code (output parsing) in a template, between {exp:channel:calendar} tags. I have a line assigning the value of a custom date field to the php variable %endDate. Then, I need to test if {date} is equal to this $endDate variable. But if I use {date} alone it just takes the string "{date}" instead of its actual value, and I think that's because that tag requires a format parameter, so now I'm tryng this:

if ("{date format="%U"}" == $endDate)

but, obviously, this gives me a php syntax error and just screws up half of the template... Any idea what syntax I should use to do this?

2
  • After some further experimentation, I realized the whole {date format="%U"} doesn't work, even outside of PHP. Just trying to display its value in plain simple HTML fails. Has anyone else encountered any problems with the {date} variable in {exp:channel:calendar} tags??
    – Penega
    Commented May 23, 2013 at 19:40
  • Something just hit me... this client's site is on EE 2.5.2... Did that variable exist back then? I can't seem to find EE's documentation for older versions...
    – Penega
    Commented May 23, 2013 at 19:49

2 Answers 2

1

I just tested this:

{exp:channel:entries limit="1"}
{title}<br />
{entry_date format="%U"}<br />
<?php
$compare_date ="1123581363";
echo $compare_date." - compare date<br />";
$e_date = {entry_date format="%U"};
echo $e_date." - E date<br />";   
if ($compare_date > {entry_date format="%U"}) {echo "I am Greater than";} else {echo "I am Less than";}
?>
{/exp:channel:entries}

Template set to php on output.

2
  • If your looking for the NOW date and time use : {current_time format="%U"} instead of {date format="%U"}
    – Jim Wyse
    Commented May 24, 2013 at 12:42
  • I'm not trying to format the entry date or current date in a channel entry tag, I'm trying to format the date variable in a calendar tag (i.e. this date: ellislab.com/expressionengine/user-guide/modules/channel/…) And {date format="%U"} doesn't work at all so I'm guessing this variable wasn't available in EE 2.5.2., so I found another way to do what I wanted to without using the variable. Thank you anyway
    – Penega
    Commented May 24, 2013 at 13:35
0

First of all your code if ("{date format="%U"}" == $endDate) isn't correct and you couldn't compare the a PHP variable with EE variable with EE's IF condition due to parsing stage.

The variable {date format="%U"} will work if you are have "date" as Date type field and it will return seconds since the epoch.

You can try the condition code like: if ("{date format="%U"}" == "<?php echo $endDate; ?>) make sure the "PHP Parsing Stage" is selected as "Input". But I am not sure if it would work properly for you as you are putting the condition within channel entry tag and where assign the value for PHP variable $endDate.

1
  • I'm not using EE's if condition. This is a PHP line. It's a PHP if condition. And it's not in a channel entry tag, it's in a calendar tag, and date is a variable available for calendar tags, not a field.
    – Penega
    Commented May 24, 2013 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.