Reputation: 65
I've a custom page for Wordpress where I check if a ACF (advanced custom field) date value (sorted m-d-Y) is < = > of date(m-d-Y). If ACF value have 2016 year all work, if year is 2017 function doesn't work.
example of code:
if (get_sub_field('data_inizio') >= date('m-d-Y')) {
}
If I replace date('m-d-Y') with 01-01-2017 work.
Thanks for your help.
Upvotes: 4
Views: 1814
Reputation: 21
You have to covert this strings to DateTime
objects and then compare them... You can compare strings only to see if they are equal.
Upvotes: 0
Reputation: 5371
You are currently comparing two strings. You can convert them to unix time and compare them that way, or convert the strings to DateTime objects and compare those.
Example of using unix time to figure out if data_inizio date is in past:
if(strtotime(get_sub_field('data_inizio')) <= time()) {
}
Upvotes: 2