note 78761 modified in ref.datetime by danbrown

From: Date: Sun, 20 Jul 2008 02:20:49 +0000
Subject: note 78761 modified in ref.datetime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141952@lists.php.net to get a copy of this message
May be useful for somebody. This function takes on daylight saving time <?php Function DateDiff($date1,$date2) { $timedifference=$date2-$date1; $corr=date("I",$date2)-date("I",$date1); $timedifference+=$corr; return $timedifference; } ?> Example: <?php $d1=mktime(2,0,0,10,28,2007); $d2=mktime(4,0,0,10,28,2007); $period=DateDiff($d1,$d2); printf("<br>%s",date("I d.m.Y H:i",$d1)); printf("<br>%u hour",$period/3600); printf("<br>%s",date("I d.m.Y H:i",$d2)); ?> Getting 2 hour instead 3. --was-- May be useful for somebody. This function takes on daylight saving time Function DateDiff($date1,$date2) { $timedifference=$date2-$date1; $corr=date("I",$date2)-date("I",$date1); $timedifference+=$corr; return $timedifference; } Example: $d1=mktime(2,0,0,10,28,2007); $d2=mktime(4,0,0,10,28,2007); $period=DateDiff($d1,$d2); printf("<br>%s",date("I d.m.Y H:i",$d1)); printf("<br>%u hour",$period/3600); printf("<br>%s",date("I d.m.Y H:i",$d2)); Getting 2 hour instead 3. http://php.net/manual/en/ref.datetime.php

« previous php.notes (#141952) next »