note 54516 added to function.jdtogregorian
| From: | pctips at osu1 dot php dot net | Date: | Wed, 06 Jul 2005 21:12:16 +0000 |
| Subject: | note 54516 added to function.jdtogregorian | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91552@lists.php.net to get a copy of this message | ||
I have changed treebe's function a bit:
function jd_to_greg($julian) {
$julian = $julian - 1721119;
$calc1 = 4 * $julian - 1;
$year = floor($calc1 / 146097);
$julian = floor($calc1 - 146097 * $year);
$day = floor($julian / 4);
$calc2 = 4 * $day + 3;
$julian = floor($calc2 / 1461);
$day = $calc2 - 1461 * $julian;
$day = floor(($day + 4) / 4);
$calc3 = 5 * $day - 3;
$month = floor($calc3 / 153);
$day = $calc3 - 153 * $month;
$day = floor(($day + 5) / 5);
$year = 100 * $year + $julian;
if ($month < 10) {
$month = $month + 3;
}
else {
$month = $month - 9;
$year = $year + 1;
}
if ($day < 10) {
$day = "0".$day;
}
if ($month < 10) {
$month = "0".$month;
}
return $day."/".$month."/".$year;
}
So, if the in the old format the 1st January 2005 was "1.1.2005", now the function will
return "01/01/2005". I hope it could be useful to someone :)
----
Manual Page -- http://www.php.net/manual/en/function.jdtogregorian.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54516
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54516&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54516&report=yes
Search -- http://master.php.net/manage/user-notes.php