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 dates doesn't work after upgrade to 2.2.2

September 05, 2011 12:41pm

Subscribe [2]
  • #1 / Sep 05, 2011 12:41pm

    Dragan Simonovic

    71 posts

    This question may be related to a resolved thread.

    The following code worked in 2.2.1 but after upgrading to 2.2.2 the code doesn’t work

    {if "{entry_date format='%d%m%Y'}" < "26082011"}Display something{if:else}Display something else{/if}

    Any idea why this code doesn’t work in 2.2.2 and used to work in 2.2.1?

    Thanks in advance!

  • #2 / Sep 06, 2011 11:37am

    Mark Bowen

    12637 posts

    Hi Vibrant Drive,

    Usually in the past when I’ve done this kind of thing I’ve used the $U date format as that then allows you to utilise comparisons a lot easier.

    I’m not entirely certain how that used to work for you as I thought that the < comparison operator there just took the numbers literally and not as a date.

    I’d definitely therefore recommend using the %U format for this kind of thing instead.

    Does that help at all?

    Thanks.

    Mark

  • #3 / Sep 06, 2011 11:44am

    Dragan Simonovic

    71 posts

    Hi Mark,

    I’ll give another try to Unix time but when I tried using it, the final result is the same.

    I think you’re right about < comparison operator there just took the numbers literally and not as a date.

    I have a static date to compare against entry_date because the website I build is a huge news portal and now we’re using new module for managing assets but I still need to display old assets. So the easiest way is to compare entry_date with a static date when we started to use new assets module.

  • #4 / Sep 06, 2011 6:37pm

    Mark Bowen

    12637 posts

    Hi Vibrant Drive,

    You should definitely get better results using the %U format than using a date although saying that are you using that you mention using a new module?

    Are you now using that {if} statement within the new modules tags perhaps?

    If so then it might be that the module doesn’t like that which is something you would need to take up with the author of that module as we can’t offer support for 3rd party offerings I’m afraid.

    That said I’d definitely advise using &U though.

    Does that help at all?

    Thanks.

    Mark

  • #5 / Sep 06, 2011 7:21pm

    Dragan Simonovic

    71 posts

    Hi Mark,

    I’m using {if} statement in native way and outside of new module tags. It’s like this:

    {if "{entry_date format='%U'}" < "static_date_converted_to_unix_time"}
    Old assets code
    {if:else}
    New assets code
    {/if}

    But for some reason, always display only first rule (old assets code).

  • #6 / Sep 06, 2011 9:30pm

    Mark Bowen

    12637 posts

    Is that {if} conditional surrounded by a Channel Entries tag, something else or nothing?

    Have you tried just outputting the date in each of the {if} conditionals so something like this :

    {if "{entry_date format='%U'}" < "static_date_converted_to_unix_time"}
    {entry_date format='%U'} - static_date_here
    {if:else}
    {entry_date format='%U'} - static_date_here
    {/if}

    Where it says static_date_here in the code above place in the date Unix date that you have converted so you can very quickly see if the numbers you are getting output are being evaluated by the conditional correctly.

    Also for now take out the assets module (I’m guessing this is the Pixel & Tonic module you’re using here?) whilst you’re testing this.

    Let me know how you get on with that please.

    Thanks.

    Mark

  • #7 / Sep 07, 2011 5:37pm

    Dragan Simonovic

    71 posts

    Hi Mark,

    I just tried with Unix time and seems like everything works as expected.

    Thanks for your help!

  • #8 / Sep 07, 2011 6:07pm

    Mark Bowen

    12637 posts

    Hi Mark,

    I just tried with Unix time and seems like everything works as expected.

    Thanks for your help!

    Excellent news!

    Glad that got it working for you.

    If you have any more issues then please feel free to post again as needed.

    Cheers,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases