This question already has an answer here:
I need one help.I have an issue while comparing two date inside if condition.I am explaining my code below.
$erresult = mysqli_fetch_array($qrylast);
$ticket = $erresult['ticket_id'];
if ((date("Y-m-d") == $erresult['date'])) {
$id = sprintf("%03d", $ticket++);
$fields = array("date", "ticket_id ");
$tablename = "db_ticket";
$values = array(date("Y-m-d"), $id);
$id1 = db_insert($tablename, $values, $fields);
if ($id1) {
$ticket_id = 'W1' . date("Ymd") . $id;
}
} else {
$id = '001';
$fields = array("date", "ticket_id ");
$tablename = "db_ticket";
$values = array(date("Y-m-d"), $id);
$id1 = db_insert($tablename, $values, $fields);
if ($id1) {
$ticket_id = 'W1' . date("Ymd") . $id;
}
}
here i need to compare today's date with date save inside database.my saved date inside database datatype is also date but here always else part is executing.In my code i have one condition (date("Y-m-d")==$erresult['date'])
and this condition is never executing even two date are same.Please help me to resolve this issue.
</div>
Try
if(strtotime(date("Y-m-d")) == strtotime($erresult['date']))
follow :- How to compare two dates in php
You can use the strtotime()
function to compare the two dates e.g
if(strtotime(date("Y-m-d")) == strtotime(date("Y-m-d",$erresult['date'])))