note 61835 added to function.date

From: Date: Mon, 13 Feb 2006 12:49:09 +0000
Subject: note 61835 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-103620@lists.php.net to get a copy of this message
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; } ---- Server IP: 203.199.107.94 Probable Submitter: 61.16.136.226 (proxied: 61.16.136.226) ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61835 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61835&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61835&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103620) next »