Trying to do a simple date comparison. Both dates are in the format of "Y F jS, g:i a". e.g. 2018 September 3rd, 9:30 am.
$today = date('Y F jS, g:i a');
$expire = file_get_contents(dirname(__FILE__).'/maintenance/end_time.php');
if($today>$expire){
unlink(dirname(__FILE__).'/maintenance/end_time.php');
}
The code I have doesn't work correctly. I also tried strototime() but that was also unsuccessful.
Try this.
$today_dt = new DateTime($today);
$expire_dt = new DateTime($expire);
if ($today_dt > $expire_dt)
{ /* Do something */ }
Update: It might possible that the date string is not supported by DateTime parser so you can initialize your dates like this.
$today_dt = DateTime::createFromFormat('Y F jS, g:i a', $today);
$expire_dt = DateTime::createFromFormat('Y F jS, g:i a', $expire);
Use strtotime
$today = time();
$expire = strtotime(file_get_contents(dirname(__FILE__).'/maintenance/end_time.php'));
if($today>$expire){
//code
}
OR
$today = date('Y F jS, g:i a');
$expire = file_get_contents(dirname(__FILE__).'/maintenance/end_time.php');
if(strtotime($today) > strtotime($expire)){
unlink(dirname(__FILE__).'/maintenance/end_time.php');
}