note 61835 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:43:26 +0000 |
| Subject: | note 61835 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114251@lists.php.net to get a copy of this message | ||
Note Submitter: contactbablu at yahoo dot com
----
Hear is a function which calculate date difference between provided one and current time stamp. You
can modify this function to calculate difference between two provided argument to function.
function date_format($tstamp)
{
$y=date('Y',$tstamp);
$m=date('n',$tstamp);
$d=date('d',$tstamp);
$h=date('G',$tstamp);
$i=date('i',$tstamp);
$s=date('s',$tstamp);
//c stand for current
//
//***************
change value between * A/C to your needs
$cy=date('Y');
$cm=date('n');
$cd=date('d');
$ch=date('G');
$ci=date('i');
$cs=date('s');
//
if(is_leep($cy))
{
$marray=array('1'=>31,'2'=>29,'3'=>31,
'4'=>30,'5'=>31,'6'=>30,
'7'=>31,'8'=>31,'9'=>30,
'10'=>31,'11'=>30,'12'=>31);
}
else
{
$marray=array('1'=>31,'2'=>28,'3'=>31,
'4'=>30,'5'=>31,'6'=>30,
'7'=>31,'8'=>31,'9'=>30,
'10'=>31,'11'=>30,'12'=>31);
}
//
//for second
if($cs >= $s)
{
$s=$cs-$s;
}
else
{
$ci--;
$cs=$cs + 60;
$s=$cs-$s;
}
//for minutes
if($ci >= $i)
{
$i=$ci-$i;
}
else
{
$ch--;
$ci=$ci + 60;
$i=$ci-$i;
}
//for hour
if($ch >= $h)
{
$h=$ch-$h;
}
else
{
$cd--;
$ch=$ch + 60;
$h=$ch-$h;
}
//days
if($cd >= $d)
{
$d=$cd-$d;
}
else
{
$temp=$marray[$cm];
$cm--;
$cd=$cd + $temp;
$d=$cd-$d;
}
//for month
if($cm >= $m)
{
$m=($cm - $m);
}
else
{
$cy--;
$cm=$cm + 12;
$m=$cm-$m;
}
//for year
$y=$cy-$y;
//
$date=$y." Year-".$m." Month-".$d." Days<br>".$h." Hours
-".$i." Min-".$s." Second";
return $date;
}
//check whether leep year or not
function is_leep($y)
{
if($y % 4 == 0 && $y % 100 != 0)
{
return 1;
}
if($y % 100 == 0 && $y % 400 == 0)
{
return 1;
}
return 0;
}