note 76993 added to function.jdtogregorian

From: Date: Thu, 09 Aug 2007 10:10:41 +0000
Subject: note 76993 added to function.jdtogregorian
Groups: php.notes 
Request: Send a blank email to php-notes+get-129370@lists.php.net to get a copy of this message
<?php // original script: // http://www.codeproject.com/datetime/exceldmy.asp // Excel/Lotus 123 have a bug with 29-02-1900. // 1900 is not a leap year, but Excel/Lotus 123 think it is... function excel_D2DMY($days) { if ($days <1) return ""; if ($days == 60) { return array('day'=>29,'month'=>2,'year'=>1900); } else { if ($days < 60) { // Because of the 29-02-1900 bug, any serial date // under 60 is one off... Compensate. ++$days; } // Modified Julian to DMY calculation with an addition of 2415019 $l = $days + 68569 + 2415019; $n = floor(( 4 * $l ) / 146097); $l = $l - floor(( 146097 * $n + 3 ) / 4); $i = floor(( 4000 * ( $l + 1 ) ) / 1461001); $l = $l - floor(( 1461 * $i ) / 4) + 31; $j = floor(( 80 * $l ) / 2447); $nDay = $l - floor(( 2447 * $j ) / 80); $l = floor($j / 11); $nMonth = $j + 2 - ( 12 * $l ); $nYear = 100 * ( $n - 49 ) + $i + $l; $ret = array('day'=>$nDay,'month'=>$nMonth,'year'=>$nYear); return $ret; } } /** * @desc Returns Excel serialDate constant calculated from gregorian date * original javascript found @ http://wwwmacho.mcmaster.ca/JAVA/JD.html * ported to PHP by XL:-) * * tested compatibility with EXCEL dates between 01/01/1900..31.12.2099, * year given eventually as 0 (=1900)..199 (=2099) * adds also days if supplied argument more than real number of days * in particular month (same applies to months) * as for years bellow 1900: algorhytm is not exact, therefore limitation * for years 1900 - 2099 */ function excel_DMY2D($d, $m, $y, $uh=0, $um=0, $us=0) { if($y<1900){ if($y<0 || $y>199){ echo ' !!! Invalid year ['.$y.'], must be between 1900 - 2099 or 0 - 199 !!!'; return false; }else{ $y += 1900; } } $extra = 100.0*$y + $m - 190002.5; $rjd = 367.0*$y; $rjd -= floor(7.0*($y+floor(($m+9.0)/12.0))/4.0); $rjd += floor(275.0*$m/9.0); $rjd += $d; $rjd += ($uh + ($um + $us/60.0)/60.)/24.0; $rjd += 1721013.5; $rjd -= 0.5*$extra/abs($extra); $rjd += 0.5; $rjd -= 2415020.5; // JD correction constant for 01/01/1900 $rjd += ($rjd>60) ? 2 : 1; // adjust to inheritet EXCEL/LOTUS bug return $rjd; } ?> ---- Server IP: 195.46.80.5 Probable Submitter: 212.26.186.70 ---- Manual Page -- http://www.php.net/manual/en/function.jdtogregorian.php Edit -- https://master.php.net/note/edit/76993 Del: integrated -- https://master.php.net/note/delete/76993/integrated Del: useless -- https://master.php.net/note/delete/76993/useless Del: bad code -- https://master.php.net/note/delete/76993/bad+code Del: spam -- https://master.php.net/note/delete/76993/spam Del: non-english -- https://master.php.net/note/delete/76993/non-english Del: in docs -- https://master.php.net/note/delete/76993/in+docs Del: other reasons-- https://master.php.net/note/delete/76993 Reject -- https://master.php.net/note/reject/76993 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129370) next »