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.

compare entry date with todays date

June 09, 2008 12:13pm

Subscribe [5]
  • #1 / Jun 09, 2008 12:13pm

    Studio Hert

    36 posts

    Hi

    In my detail from e weblog entry, i want to insert a conditional. I want to check if the entry_date is before or after the current date. I know about the start_on and stop_before parameters, but that’s not what I want. I want to display the whole post, doesn’t matter when the entry date is, but only show a certain sentence if that post has an entry_date greater than today.

    Who can help me out?


    Thanx a lot

    Bart

  • #2 / Jun 09, 2008 4:47pm

    e-man

    1816 posts

    Not a cut and paste solution but I’m sure you’ll get the idea:

    {exp:weblog:entries weblog="newblog" disable="categories|member_data|trackbacks|pagination" limit="10"}
    <?php $today=strtotime("now");
    $the_date= "{entry_date}";
    if ($the_date > $today) { ?>
    Your sentence here    
    <?php } else { ?>
    Your EE output here {body} etc…    
    <?php } ?>
    {/exp:weblog:entries}

    enable php and set parsing to output in your template.

  • #3 / Jun 09, 2008 4:58pm

    Ingmar

    29245 posts

    PHP’s all well, of course, but not strictly needed in this case, I think: You could simply compare {entry_date} and {current_time}.

  • #4 / Jun 09, 2008 5:01pm

    e-man

    1816 posts

    D’oh!  😊

  • #5 / Jun 09, 2008 5:11pm

    Studio Hert

    36 posts

    Hi

    Well, I tried to compqre {entry_date} and {current_time}, but it gave me an error. I don’t know what I am doing wrong. Can somebody give me the right way to do it? (Without php)

  • #6 / Jun 09, 2008 5:16pm

    Ingmar

    29245 posts

    You could probably assign some format= to your date variable. %U (UNIX Timestamp) works best if you use it only for comparison purposes:

    {if "{entry_date format='%U'}" > "{current_time format='%U'}"}
    
    foo
    
    {/if}

    Give that a try, will you?

  • #7 / Jun 09, 2008 5:22pm

    Studio Hert

    36 posts

    ok thanx a lot
    coming from a php background, i’m not into the curly-brackets-thing. I think it looked a bit strange. Thanks!

  • #8 / Jun 09, 2008 5:28pm

    Ingmar

    29245 posts

    It’s pretty straight forward, once you get used to it. Curly quotes serve double duty here for EE variables, not just to delimit functions, clauses and such, the way they do in PHP.

  • #9 / Jun 16, 2008 5:47pm

    grantmx

    1439 posts

    I tried this:

    {if "{entry_date format='%U'}" > "{current_time format='%U'}"}foo{/if}

    and it throws back an error.

    Parse error: syntax error, unexpected T_STRING in /.../core/core.functions.php(637) : eval()‘d code on line 3

    ————

    Ultimately I need to do something more complex like this:

    {if "{expiration_date format='%D, %F %d, %Y - %g:%i:%s'}" > "{current_time format='%D, %F %d, %Y - %g:%i:%s'}" AND "{entry_date format='%D, %F %d, %Y - %g:%i:%s'}" < "{current_time format='%D, %F %d, %Y - %g:%i:%s'}"} foo {/if}

    But errs. Any ideas?  I’m trying to schedule the LG Poll module, but Mr. L.G. didn’t build in a way to “schedule” or make polls appear on their entry date.  They just start on the entry date (and indicate so-only) as well as close on their expiration date (and just indicate so).

    This poll closed on {expiration_date format="%D, %F %d, %Y - %g:%i:%s"}

    He told me that I could create a conditional statement, but I am having a bit of trouble with the logic.

    Thanks!

  • #10 / Jun 17, 2008 9:57am

    grantmx

    1439 posts

    bump.  :coolmad:

  • #11 / Sep 23, 2008 2:33am

    OrganizedFellow

    435 posts

    Have you found a solution grantmx?

  • #12 / Sep 23, 2008 4:11am

    Ingmar

    29245 posts

    Sorry, it works perfectly for me as is. Make sure to be on the latest version and build, and get your chars right (beware the typographical quote).

  • #13 / Sep 23, 2008 10:00am

    grantmx

    1439 posts

    Nothing viable.  Wound up doing it manually for the time being.

  • #14 / Sep 23, 2008 10:03am

    Ingmar

    29245 posts

    Funny… As I’ve said, it works “as is” for me. Flawlessly.

  • #15 / Sep 23, 2008 10:06am

    grantmx

    1439 posts

    You used my syntax and used it with the Poll module?  Interesting…

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

ExpressionEngine News!

#eecms, #events, #releases