note 80246 added to function.date

From: Date: Sat, 05 Jan 2008 21:33:14 +0000
Subject: note 80246 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-134839@lists.php.net to get a copy of this message
This function calculaties the days between two data (Ymd) By example, if $datum1 = 20071215 and $datum2 = 20081215, the output will be 366 ;-) <?php function calculate_day_between($datum1,$datum2) { if( is_numeric($datum1) && is_numeric($datum2) && strlen($datum1) == 8 && strlen($datum2) == 8 ) { $dat = ($datum1 < $datum2)? $datum1 : $datum2; $datv = ($datum1 < $datum2)? $datum2 : $datum1; $i = 0; while( $dat < $datv) { $i++; switch(substr($dat,6,2)) { case '28': $dat += (substr($dat,4,2) == 02 && substr($dat,0,4)%4 > 0 )? 73 : 1; break; case '29': $dat += (substr($dat,4,2) == 02 && substr($dat,0,4)%4 == 0 )? 72 : 1; break; case '30': $dat += (in_array( substr($dat,4,2), array(04,06,09,11)))? 71 : 1; break; case '31': $dat += (substr($dat,4,2) == 12 )? 8870 : 70; break; default: $dat++; break; } } return $i-1; } else { return false; } } ?> ---- Server IP: 87.238.162.147 Probable Submitter: 213.119.75.13 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/80246 Del: integrated -- https://master.php.net/note/delete/80246/integrated Del: useless -- https://master.php.net/note/delete/80246/useless Del: bad code -- https://master.php.net/note/delete/80246/bad+code Del: spam -- https://master.php.net/note/delete/80246/spam Del: non-english -- https://master.php.net/note/delete/80246/non-english Del: in docs -- https://master.php.net/note/delete/80246/in+docs Del: other reasons-- https://master.php.net/note/delete/80246 Reject -- https://master.php.net/note/reject/80246 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134839) next »