ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

{comment_date} issue

April 24, 2013 6:46pm

Subscribe [2]
  • #1 / Apr 24, 2013 6:46pm

    wornjacket

    98 posts

    Any ideas how to convert this string to something that I can perform math functions on in PHP?

    I’ve tried intval() and strtotime() but it isn’t working. Is there a built-in method I can use?

  • #2 / Apr 25, 2013 1:54am

    travisb

    172 posts

    Would something like the following help, with php on output?

    <?php
    
    $comment_date_var = $this->EE->localize-> string_to_timestamp({comment_date}); 
    
    ?>

    (I haven’t tested, but info here may help)

  • #3 / Apr 25, 2013 1:22pm

    wornjacket

    98 posts

    Hey thanks.

    I tried that from the docs, and it seems that no matter what format I pass the stored comment_date timestamp as (e.g. {comment_date format="%r") ) when I run it through the localize string_to_timestamp() it returns: invalid_date_formatting.

    Here's the code I have:

    $stored_comment_Date = '{comment_date format="%r"}'; // stored as numeric timestamp STRING
    $converted_comment_Date = $this->EE->localize->string_to_timestamp($stored_comment_Date, FALSE); // yields invalid_date_formatting
  • #4 / Apr 25, 2013 2:02pm

    travisb

    172 posts

    Ok, I haven’t tested your exact code, but did get this working and maybe you can use it to work off of:

    <?php
    
    $comment_date_var = $this->EE->localize->string_to_timestamp("{comment_date format="%Y-%m-%d %g:%i %A"}");
    
    echo "COMMENT_DATE_VAR: " . $comment_date_var . " END";
    
    ?>
  • #5 / Apr 25, 2013 3:00pm

    wornjacket

    98 posts

    Travis,

    Thanks again this seems like an easy thing to accomplish and its still returning the same error when I format the {comment_date} like you have above.

    If i take your code exactly I get the following error: Parse error: syntax error, unexpected ‘%’

    Currently running EE 2.5.2 do you think this is the issue?

  • #6 / Apr 25, 2013 3:15pm

    travisb

    172 posts

    I ran the test on 2.5.3 with php set to output, so not sure if that would affect anything or not. Did you make sure to run the code within the exp:comment:entries tag pair?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases