note 56199 added to function.time
| From: | amit_sandilya at hotmail dot com | Date: | Fri, 26 Aug 2005 16:44:47 +0000 |
| Subject: | note 56199 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94231@lists.php.net to get a copy of this message | ||
a date function to return day difference between two dates. And if first date is greater than second
date it return -1, if second date is greater than first date it returns 1, otherwise it returns o.
function date_compare($date1,$date2)
{
$time1=strtotime($date1);
$time2=strtotime($date2);
$day_count=0;
if($time2>$time1)
{
$time3=$time1;
for($i=$time3;$i<$time2;)
{
list($fy,$fm,$fd) = explode("-",$date1);
$date1= date("Y-m-d",mktime(0,0,0,$fm,$fd+1,$fy));
$time3=strtotime($date1);
if($time3==$time2)
{
$i=$time2;
}
$i=$time3;
$day_count++;
}
$val=1;
}
if($time1>$time2)
{
$time3=$time2;
for($i=$time3;$i<$time1;)
{
list($fy,$fm,$fd) = explode("-",$date2);
$date2= date("Y-m-d",mktime(0,0,0,$fm,$fd+1,$fy));
$time3=strtotime($date2);
if($time3==$time1)
{
$i=$time1;
}
$i=$time3;
$day_count++;
}
$val=-1;
}
elseif($time1==$time2)
{
$val=0;
}
return array($val,$day_count);
}
examples:-
$date1="2005-08-26";
$date2="2004-09-28";
$aa=date_compare($date1,$date2);
print_r($aa);
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56199
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56199&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56199&report=yes
Search -- http://master.php.net/manage/user-notes.php