Comparing date with today date using strtotime
Posted: 11 Dec 2014, 07:57
I've written following code to compare a date in a variable with today's date. If the date in a variable is greater than today's date the error message should be echoed. But it's not working properly in my case.
Actually today's date is 12-11-2014 (11th December 2014) and I'm indirectly comparing today's date with itself. So I should not get an error message since the date I'm comparing is not greater than today's date, but I'm getting the error message.
So how should I resolve this issue?
Code: Select all
$form_data['trans_date'] = '12-11-2014'; // Date to be compared with today's date in mm-dd-yyyy format
if(strtotime(date('m-d-Y')) < strtotime($form_data['trans_date'])) echo 'Error'; // if greater than today's date
else echo 'Success';
So how should I resolve this issue?