Search code examples
phpdatepostbackautopostbackpostbackurl

Warning: date() expects parameter 2 to be long, string given


An error:

Warning: date() expects parameter 2 to be long

This is a postback php scripts part,

$conv_time = time();
$click_time_to_date = new DateTime(date('Y-m-d h:i:s', $mysql['click_time']));
$conv_time_to_date = new DateTime(date('Y-m-d h:i:s', $conv_time));
$diff = $click_time_to_date->diff($conv_time_to_date);
$mysql['time_difference'] =  $db->real_escape_string($diff->d.' days, '.$diff->h.' hours, '.$diff->i.' min and '.$diff->s.' sec');
$mysql['conv_time'] = $db->real_escape_string($conv_time);
$mysql['ip'] = $db->real_escape_string($_SERVER['HTTP_X_FORWARDED_FOR']);
$mysql['user_agent'] = $db->real_escape_string($_SERVER['HTTP_USER_AGENT']);

Solution

  • Your click_time field probably is of type DATETIME, and date() expects the second parameter to be a timestamp (long).

    Try replacing line #2 with:

    $click_time_to_date = new DateTime($mysql['click_time']);
    

    Or make sure that your click_time field is of type TIMESTAMP.