php - How to correctly compare "year" using strtotime in the included script
My error validation isn't working. I have tried so many different methods and it seems like maybe the year is not a valid comparison. Please tell me if the example code looks good and the problem must exist somewhere else.
Here is my script:
if( isset( $arr_posts['group_event_start'] ) && date("Y",strtotime($arr_posts['group_event_start']) >= date("Y") ) ){
UM()->form()->add_error('group_event_start', __(date('Y',strtotime($arr_posts['group_event_start'])). ' You must enter a valid start date/time.','um-groups') );
}
Here is a sample date: 01/01/2021 12:00 AM
The error message is outputting the following: 2021 You must enter a valid start date/time.
This shows that it is recognizing 2021 but not comparing it correctly with date("Y), doesn't it? 2021 is clearly greater than 2020.
I have even removed the first argument of the conditional just using the date comparison only. It never validates correctly.
What am I missing?
Answer
Solution:
I see one date() inside the other date() following parenthesis order.
Maybe you are trying to compare date("Y") >= date("Y"), so you would need to change the parenthesis.
Source