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.

Tip: How To Determine If Entry Date Is Today

September 13, 2010 10:54am

Subscribe [3]
  • #1 / Sep 13, 2010 10:54am

    three80

    15 posts

    I had to figure this out for my site, so I thought I’d share how I did it.  It’s simple enough, but you have to know the right code to make it work.

    On my blog homepage, for posts that were posted today I want to output “Today” instead of today’s date; for all others I want to output the actual date.

    My approach was to compare the day, month and year of the post’s entry date to the day, month and year of the current date.  If they’re the same, it was posted today.

    Here’s how I do it:

    
      {if {entry_date format="%d"} == {current_time format="%d"} 
        AND {entry_date format="%m"} == {current_time format="%m"} 
        AND {entry_date format="%Y"} == {current_time format="%Y"}}
        Today
      {if:else}
        {entry_date format="%F %d"}
      {/if}
    
  • #2 / Sep 13, 2010 4:21pm

    Ingmar

    29245 posts

    Thanks for sharing your code. I’ll just move this over to the CodeShare Corner.

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

ExpressionEngine News!

#eecms, #events, #releases