We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Getting Date formatting to work?

Development and Programming

fredkelly's avatar
fredkelly
13 posts
15 years ago
fredkelly's avatar fredkelly

Hi There,

I am trying to modify a plugin so that I can use expressionengine’s built in date formatting options from within my template.

I have a variable,

$created_at

that is a UNIX timestamp. This is then outputting in the following loop:

foreach ($this->EE->TMPL->var_single as $var)
{
    //  Parse image created_at
        if ($var == 'created_at')
        {            
            $tagdata    = $this->EE->TMPL->swap_var_single($var, $created_at, $tagdata);
        }
    }
}

$this->return_data .= $tagdata;

return $this->return_data;

(I’ve cut some code out to keep it short).

From reading the User Guide, I understand that the format=”%Y %m %d” style options should be automatically available when the variable is a UNIX timestamp. However, when I attempt to add a format=”” parameter the tag does not work.

Does anyone know why this is?

Many thanks.

       
Adrian Macneil (Crescendo)'s avatar
Adrian Macneil (Crescendo)
28 posts
15 years ago
Adrian Macneil (Crescendo)'s avatar Adrian Macneil (Crescendo)

Have you tried, or is it possible in your plugin, parse_variables()?

$tag_vars = array();
$tag_vars[0]['created_at'] = 48548937;

return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $tag_vars);

I think the format=”” bit gets parsed automatically if you do that.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.