3
I am doing a test, with a query in Oracle database (recording sysdate, result: 13/09/2016 13:24:44) and returning me in PHP. I need to calculate the difference in hours and was trying the function below:
$date_a = new DateTime($p_fim[$passo]);
$date_b = new DateTime($p_inicio[$passo]);
$interval = date_diff($date_a,$date_b);
echo $interval->format('%h:%i:%s');
But is returning the error below:
Fatal error: Uncaught Exception 'Exception' with message 'Datetime::__Construct(): Failed to parse time string (13/09/2016 13:24:44) at position 0 (1): Unexpected'
Searching the same OS everyone uses the format 2016-09-13. Is that right? Need to convert before passing the value?
Yes, the
date_diff
only accepts the separate date string with hyphen.-
, for example;13-09-16
, test them and let me know if you succeed! then put as response!– RFL
Try this: ALTER SESSION SET NLS_DATE_FORMAT = '[date_format]'
– Reginaldo Rigo