Home › Forums › General Issues › Comparing Dates › Reply To: Comparing Dates
In order to compare them this way you need to convert the field to a unix time value. The return value of the field needs to be in a format that will be recognized by strtotime()
see http://php.net/manual/en/function.strtotime.php
and http://php.net/manual/en/datetime.formats.php
$time = strtotime(get_field('date_field_name'));
$now = time();
if ($time < $now) {
// .....
}
Edit:
Also, new DateTime()
creates a date/time object which cannot be compared to a string. It may be possible to use this object but it will take a lot more code to extract the string you want from it. I can’t help you with that because I personally use the simpler functions for dates and time rather than using this object.
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.