note 94901 deleted from function.date by danbrown
| From: | danbrown@php.net | Date: | Wed, 02 Dec 2009 15:08:39 +0000 |
| Subject: | note 94901 deleted from function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163497@lists.php.net to get a copy of this message | ||
Note Submitter: vilas_sha at yahoo dot com
----
<?php
//this function can be used to calculate the number of years and months experiance of a employee in
a company.
//example 4.6 means 4 years 6 months.
$dateofjoin="2007-11-01";
$date_diff=calculate_date_diff($$dateofjoin);
echo $date_diff;
function calculate_date_diff($doj1)
{
$doj1=strtotime($doj1);
$doj=date("m/d/Y",$doj1);
$now=date("m/d/Y"); //this can be changed as the date you want. I am calculating till
date
$year=date("Y");
$x=explode("/",$doj);
$y1=explode("/",$now);
$yy=$x[2];
$mm=$x[0];
$dd=$x[1];
$yy1=$y1[2];
$mm1=$y1[0];
$dd1=$y1[1];
$mn=0;
$mn1=0;
$ye=0;
if($mm1>$mm)
{
$mn=$mm1-$mm;
if($dd1<$dd)
{
$mn=$mn-1;
}
$ye=$yy1-$yy;
}
else if($mm1<$mm)
{
$mn=12-$mm;
if($mm!=1)
{
$mn1=$mm1-1;
}
$mn+=$mn1;
if($dd1>$dd)
{
$mn+=1;
}
$yy=$yy+1;
$ye=$yy1-$yy;
}
else
{
$ye=$yy1-$yy;
$ye=$ye-1;
$mn=12-1;
if($dd1>$dd)
{
$ye+=1;
$mn=0;
}
}
//$to=$ye." years and ".$mn." months"; //this can be echoed to view
return $ye.".".$mn;
}
?>