- date_diff: documentation ( source)
- date_create: documentation ( source)
- json_encode: documentation ( source)
<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
$return_string=array(y=>$interval->format('%y'),"m"=>$interval->format('%m'),"d"=>$interval->format('%d'),"h"=>$interval->format('%h'),"i"=>$interval->format('%i'),"s"=>$interval->format('%s'));
$return_json=json_encode($return_string, JSON_FORCE_OBJECT);
echo $return_json;