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.

How can I compare a date custom field to current_time?

October 16, 2011 10:14pm

Subscribe [2]
  • #1 / Oct 16, 2011 10:14pm

    Omkar N.

    177 posts

    My weblog has a few standard fields (summary and body) and I’m adding a custom date field (eventdate) that holds information about the date of a future event.  Not all entries will have an eventdate.  I’d like to display the linked title of all future events: 

    Upcoming Events
    ———————-
    10/19 - Event 1
    10/22 - Event 2

    Any ideas on how I can do this using out of the box EE functionality?

    Questions:
    1. Is there a way to specify the weblog:entries tag to only return weblog entries where eventdate != “”? Or where eventdate > current_time?
    2. If I have to do that comparison inside the weblog:entries tag, how do I do so?  I tried {if eventdate > current_time} but it didn’t work for me.

  • #2 / Oct 17, 2011 10:54am

    Mark Bowen

    12637 posts

    Hi Omkar,

    With built-in functions I don’t believe there will be an easy way to do this with the Channel Entries Tag alone.

    There is a search://field_name=”“ parameter although this is reported as only working with Text Input, Textarea and Drop-down Lists fields.

    That would normally allow you to only bring back entries where a certain field has content although if you are using a date field here then that may well not work due to the restriction on fieldtypes that it works with. Wouldn’t harm to give it a go though 😉

    Other than that you would need to create a custom SQL query to get the information you need here.

    With regards to your second question to do date comparisons you will normally do something like this :

    {if "{event_date format='%U'}" > "{current_time format='%U'}"}
    Do this
    {/if}

    Hopefully that will work for you here.

    Does that help at all?

    Thanks,

    Mark

     

  • #3 / Oct 17, 2011 12:16pm

    Omkar N.

    177 posts

    Hi Mark,

    Thank you, that REALLY helped me out!

    As you said, the search:field_name did NOT work on my event_date field.  But I also have a Text Input field called event_title which gets populated together with event_date so I used search:event_title = “not IS_EMPTY” and that returns only the entries that have events (i.e., those with an event_title).

    For the second bit, the code you gave me to compare to current_time worked perfectly.  This will allow me to show only future events.

    I’m so glad to be able to get this working using the built-in functions.  :D

  • #4 / Oct 17, 2011 12:19pm

    Mark Bowen

    12637 posts

    Hi Omkar,

    Excellent news! Glad that helped out a bit and glad that you have everything working here now.

    If anything else crops up then please don’t hesitate to post again as needed.

    Cheers,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases