Home Forums General Issues Select a range between two dates


Select a range between two dates

  • Hi. I love ACF plugin.
    However, I can’t find any topic where it’s treated the dates range.
    Let’s suppose an scenery where I have to select two dates to indicate the start and end of one event (like a travel). I could use two date fields, one for the date start and one for the date end, but ACF won’t check if the end date is after than the start date. It’s why I thought a dates range would solve this problem.
    Is this something easy to do? or is there another approach to achieve that?
    Thanks in advance.

  • There are possibly two solutions.

    The first and easiest is to use two date fields, like you suggest and assume that the person creating the dates understands that the end date should be after the start date. This is what I’d do.

    The second would be to build custom JavaScript for your end date field and not allow dates that are before the start date. I would only do this if someone insisted.

  • Hey John.
    I wanted to use a date range in order to the admin interface be more user friendly. Maybe I suggest to ACF developer team consider this requirement as a new feature. What do you think?
    Another question: Your second approach, I have no idea how to do it. Should this script be in functions.php or using the “Conditional Logic” field (I’ve never used it)?
    Best regards

  • You can read about adding custom JavaScript for ACF here

    beyond that I’d be of little help. I have avoided using custom JS. Basically you’d need to detect the change of the end date field then get the value for the start date field and then alert an error if it’s not later.

    Like I said, I don’t know exactly how to do it. I could figure it out if it was necessary. while doing this would be a nice addition, it it wasn’t included in the requirements, I would not go out of my way.

    You might suggest it, but knowing what is in the conditional logic and what it can do making this part of ACF isn’t all that likely.

  • Hey John
    Thanks for your detailed answer. I’ll follow your suggestion.
    Best regards and sorry for my belated reply.

  • This reply has been marked as private.
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Select a range between two dates’ is closed to new replies.