Home › Forums › General Issues › 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.
Fernando
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 http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
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.
Fernando
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.