Format Dates:
$nonzero_task_date = array_map(function($values)
{
return date('d-m-Y', strtotime($values));
}, $nonzero_task_date);
$date_arr = array_map(function($value)
{
return date('d-m-Y', strtotime($value));
}, $date_arr);
Date array:
print_r($date_arr);
Array
(
[0] => 13-04-2015
[1] => 14-04-2015
[2] => 15-04-2015
[3] => 16-04-2015
[4] => 17-04-2015
[5] => 18-04-2015
[6] => 19-04-2015
)
print_r($nonzero_task_date );
Array
(
[0] => 16-04-2015
[1] => 14-04-2015
[2] => 13-04-2015
[3] => 16-04-2015
[4] => 17-04-2015
)
foreach ($date_arr as $row) {
//$format_date = new DateTime($row);
//$date_format = $format_date->format('d-m-Y');
//compare dates
if( (in_array($row, $nonzero_task_date)) ){
$sql = 'update query';
}
}
The above code formats the date, but fails when dates are compared using in_array()?
Also it slow down the sql process and takes time due to number of records in DB, if date formatted in foreach loop.