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.

Is there an EE equivalent to date_diff?

March 30, 2011 11:28pm

Subscribe [4]
  • #1 / Mar 30, 2011 11:28pm

    David Hyland

    210 posts

    Using EE syntax is there any way to achieve something similar to PHP’s date_diff function to work out the number of days between two given dates (in this case, the current_time and the expiry date of an entry)?

    I want to do something similar to this pseudo-code:

    {if current_time > (expiration_date - 30 days)}
    do something date related
    {/if}

    I’ve searched devot-ee and there doesn’t seem to be any plugins out there that will do this, which surprises me.

  • #2 / Mar 31, 2011 9:44am

    Sue Crocker

    26054 posts

    Hi, David. There is an EE1.x plugin http://devot-ee.com/add-ons/timesince/ that might get you started, or I can move this over to the CodeShare Corner.

    Basically, you’ll need to do some PHP code to do the math for the thirty days part.

  • #3 / Mar 31, 2011 11:45am

    David Hyland

    210 posts

    Hey Sue,

    That doesn’t really help me as I need to work out the difference in the background rather than as displayed HTML so I’ll go ahead and create my own solution.

    Cheers

    David

  • #4 / Mar 31, 2011 12:06pm

    Mark Bowen

    12637 posts

    Hi David,

    When you say “work out the difference in the background rather than as displayed HTML” what exactly do you mean by that?

    The plugin that Sue has linked to, although it might not be exactly what you need works in the kind of way you have shown using your code above. Perhaps you can show some more code of exactly what you’re trying to achieve as it might be that a plugin could be created to do what you need here.

    Best wishes,

    Mark

  • #5 / Mar 31, 2011 1:34pm

    David Hyland

    210 posts

    Hi Mark

    Okay, specifically I’m referring to the use of the Membrr subscriptions module for and the renewal date.

    I want to be able to check if the current day is within 30 days of the subscription end date so I can show a subs renewal link. The end date is stored in standard “yyyy-mm-dd hh:mm:ss” format.

    I could do it using a custom SQL query but I just wondered if there was a way to do it with EE sytax.

    Does that make sense?

    David

  • #6 / Mar 31, 2011 2:04pm

    Mark Bowen

    12637 posts

    Hi David,

    Yep that makes sense although in that case I do think that you are going to need to use some PHP to get at what you want then. That or create a plugin to handle it. Of course the plugin would be the same PHP as you’d have in a template but would just make things a bit neater.

    Best wishes,

    Mark

  • #7 / Apr 04, 2011 3:33am

    John Henry Donovan

    12339 posts

    David,

    To concur, some PHP here is the way to go. The Membrr guys might be able to give you this or it may already be in their forums somewhere

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

ExpressionEngine News!

#eecms, #events, #releases