0

Haven't used EE in a while and having a brain freeze on best way to do a date conditional.

I have a date custom field for a DOB. I want to conditional show items if the person/child is over 2 years old.

I'm thinking something along the line of:

{if ("{current_time format='%U'}" - "{child_dob format='%U'}") > '63113904'  }
    Do this
{if:else}
    Do that
{/if}

Where this would test against the Unix timestamp? Or am I way off?

1

You're on the right track, but no bracing and formatting is needed; date variables will output timestamps without formatting, and comparisons can be made properly between integer types. So you can use a simpler:

{if (current_time - child_dob) >= 63072000}
    Do this
{if:else}
    Do That
{/if}
5
  • Awesome! I'll give this a test in the morning!
    – shorn
    Jul 14 '16 at 21:30
  • Just testing this at the moment, doesn't seem to be working, although am I right in thinking that EE doesn't do maths in the template out of the box?
    – shorn
    Jul 15 '16 at 9:05
  • Math in conditionals is available since version 2.9.0 in July of 2014. Jul 15 '16 at 14:45
  • Ah, that's why. We're on an earlier version. Used a maths plugin and seems to be working ok now. Thanks!
    – shorn
    Jul 15 '16 at 15:16
  • Time to upgrade! ;) Jul 15 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.