note 114355 added to datetime.diff
| From: | taroksing at gmail dot com | Date: | Wed, 12 Feb 2014 09:14:46 +0000 |
| Subject: | note 114355 added to datetime.diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198464@lists.php.net to get a copy of this message | ||
As I needed not only to get the hours difference but also the arithmetic sign I just made this
simple function:
<?php
function calcDiffHoras($fecha1, $fecha2 = null)
{
$fecha1 = new DateTime($fecha1);
if(!$fecha2)
{
$fecha2 = new Datetime();
}
else
{
$fecha2 = new Datetime($fecha2);
}
$diff = date_diff($fecha1,$fecha2,true);
$horas = $diff->h + ($diff->days*24);
if($fecha1 < $fecha2)
{
//negative value
$horas = -1 * abs($horas);
}
else
{
$horas = $horas;
}
return $horas;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/datetime.diff.php
Edit -- https://master.php.net/note/edit/114355
Del: integrated -- https://master.php.net/note/delete/114355/integrated
Del: useless -- https://master.php.net/note/delete/114355/useless
Del: bad code -- https://master.php.net/note/delete/114355/bad+code
Del: spam -- https://master.php.net/note/delete/114355/spam
Del: non-english -- https://master.php.net/note/delete/114355/non-english
Del: in docs -- https://master.php.net/note/delete/114355/in+docs
Del: other reasons-- https://master.php.net/note/delete/114355
Reject -- https://master.php.net/note/reject/114355
Search -- https://master.php.net/manage/user-notes.php