Home › Forums › General Issues › Comparing Two Date Fields and Using an if Statement › Reply To: Comparing Two Date Fields and Using an if Statement
You need to compare the different parts. Something line this, I don’t know the exact code here so getting the month in each case is just a guess on my part.
$start_month = $start_date->format('F');
$end_month = $end_date->format('F');
if ($start_month == $end_month)) {
// output July 12-13, 2020
} else {
// output July 12 - August 3, 2020
}
I would probably also make this more complicated, comparing years as well because you might have an event that goes from Dec of one year into Jan of the next.
if ($start_year == $end_year) {
if ($start_month == $end_month) {
// output July 12-13, 2020
} else {
// output July 12 - August 3, 2020
}
} else {
// output Dec 30, 2019 - Jan 3, 2020
}
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.