Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if date is in past

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.

like image 235
lupet Avatar asked Oct 27 '25 08:10

lupet


1 Answers

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()) {

}
like image 77
skrilled Avatar answered Oct 29 '25 21:10

skrilled