What’s the right syntax to do something like this?
$this_date = {entry_date format="%Y-%m-%d"};This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
October 25, 2009 2:30pm
Subscribe [2]#1 / Oct 25, 2009 2:30pm
What’s the right syntax to do something like this?
$this_date = {entry_date format="%Y-%m-%d"};#2 / Oct 25, 2009 5:09pm
The issue is parse order related.
If you parse php on input the {entry_date format="%Y-%m-%d} will not have been parsed by EE and php will see it as a literal string. Furthermore, as you have it posted, php will cause an error since {entry_date format=""%Y-%m-%d} is not enclosed in ‘’.
If you parse php on output then EE will parse the {...} but as pointed out above it still would need to be enclosed in ‘’.
Your code would be:
<?php
$this_date = '{entry_date format="%Y-%m-%d"}';
?>#3 / Oct 25, 2009 5:34pm
Herb, thanks so much. I always have trouble with the mixed syntax. I’m very comfortable with PHP syntax but the EE template language throws me thru a loop!
Thanks so much for the great reply. This was very helpful.
#4 / Oct 26, 2009 9:53am
depending on what you’re doing with that variable within PHP, it might be easier to leave it unformatted by EE and use the PHP date functions on it.
<?php
$this_date = {entry_date}; // no quotes needed because it is an integer not a string
$this_formatted_date = date("Y-m-d", $this_date);
?>#5 / Oct 26, 2009 11:12am
Ender that’s a better solution I think! Shortly after my post that’s what I ended up doing:
$thid_date = date('Y-m-d', {entry_date});