php - strtotime to date returns false -


i have set of unix timestamps:

  1. 1473804000 1471831200

i'm not able assign date in format ('y-m-d h:i:s') each unix timestamp.

my code:

$eventhour = '1473804000'; $client = array(                 'pt' => $pt,                 'eventhour' => date('y-m-d h:i:s', $eventhour),                 'activepower' => $avg['system.avg(activepower)']             ); 

the eventhour key empty, guess function date returned false. unix timestamp valid, why returning false?

my loop code

foreach ($result $row):         $pt = $row['pt'];          $statement = new \cassandra\simplestatement("select avg(activepower) datavalue_test_by_hour pt= :pt , eventhour = :eventhour;");         $options = new \cassandra\executionoptions(             array('arguments' => array('pt' => $pt, 'eventhour' => $row['eventhour'])))         ;         $data = $this->cassandra->executewithoptions($statement, $options);         $eventhour = $row['eventhour'];         echo $eventhour . php_eol;         $avg = $data->first();         $client = array(             'pt' => $pt,             'eventhour' => date('y-m-d h:i:s', $eventhour),             'activepower' => $avg['system.avg(activepower)']         );         print_r($client);         //fputcsv($fp, $client);     endforeach; 

my print_r():

1462554000 array (     [pt] => afh0aefb0bfdei     [eventhour] =>      [activepower] => 0.02475 ) 1474887600 array (     [pt] => a0a0aeaf0di0h0     [eventhour] =>      [activepower] => 0.1115 ) 1475244000 array (     [pt] => afh0ade0ab0gdi     [eventhour] =>      [activepower] => 0.0905 ) 1473008400 array (     [pt] => a0a0aeaf0gdfhb     [eventhour] =>      [activepower] => 0.014 ) 1470693600 array (     [pt] => afh0aee00af0fg     [eventhour] =>      [activepower] => 0.051 ) 1452200400 array (     [pt] => afh0aee00bacic     [eventhour] =>      [activepower] => 0.152 ) 1463637600 array (     [pt] => afh0acfb00cd0f     [eventhour] =>      [activepower] => 0.041 ) 

i resolved issue casting returned $row['eventhour'] database int.

$eventhour = (int) $row['eventhour']; 

is working now.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -