note 95205 added to function.date

From: Date: Fri, 18 Dec 2009 11:52:46 +0000
Subject: note 95205 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-164104@lists.php.net to get a copy of this message
This function helps you to calculate exact years and months between two given dates $doj1 and $doj.. it returns example 4.3 means 4years and 3months <?php function cal_exp($doj1) { $doj1=strtotime($doj1); $doj=date("m/d/Y",$doj1); //till date or any given date $now=date("m/d/Y"); //$b=strtotime($b1); //echo $c=$b1-$a2; //echo date("Y-m-d H:i:s",$c); $year=date("Y"); //$chk_leap=is_leapyear($year); //$year_diff=365.25; $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; //$mn=$mn; 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." year and ".$mn." months"; return $ye.".".$mn; /*return daysDiff($x[2],$x[0],$x[1]); $days=dateDiff("/",$now,$doj)/$year_diff; $days_exp=explode(".",$days); return $years_exp=$days; //number of years exp*/ } ?> ---- Server IP: 202.65.157.132 Probable Submitter: 202.65.136.107 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/95205 Del: integrated -- https://master.php.net/note/delete/95205/integrated Del: useless -- https://master.php.net/note/delete/95205/useless Del: bad code -- https://master.php.net/note/delete/95205/bad+code Del: spam -- https://master.php.net/note/delete/95205/spam Del: non-english -- https://master.php.net/note/delete/95205/non-english Del: in docs -- https://master.php.net/note/delete/95205/in+docs Del: other reasons-- https://master.php.net/note/delete/95205 Reject -- https://master.php.net/note/reject/95205 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164104) next »