php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25288 Wrong JulianDayCount
Submitted: 2003-08-28 06:25 UTC Modified: 2003-09-08 06:16 UTC
From: josep dot gorro at trendcomms dot es Assigned:
Status: Not a bug Package: Calendar related
PHP Version: 4.3.1 OS: WinNT
Private report: No CVE-ID: None
 [2003-08-28 06:25 UTC] josep dot gorro at trendcomms dot es
Description:
------------
I'm generating a function to calculate a date in Julian day count to be used in excel spreadsheet. Always I obtain a 2 days difference. Is this a bug?

Reproduce code:
---------------
<?php
// This is the date that I would to convert
$jd1 = GregorianToJD (8,28,2003);
print "$jd1\n";
$gregorian1 = JDToGregorian ($jd1);
print "$gregorian1\n";
// This is the initial excel's date counter
$jd2 = GregorianToJD (1,1,1900);
print "$jd2\n";
$gregorian2 = JDToGregorian ($jd2);
print "$gregorian2\n";
// This is the REAL (not bogus) day counter
$total=$jd1 - $jd2 + 2;
print "Excel value: ".$total;
?>

Expected result:
----------------
Without the correction ($total=$jd1 - $jd2;) the result is:
2452880 8/28/2003
2415021 1/1/1900
Real counter: 37859

Whit the correction ($total=$jd1 - $jd2 + 2;) the result is:
2452880 8/28/2003
2415021 1/1/1900
Real counter: 37861

First one isn't correct, second one is fine.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-08 06:16 UTC] zak@php.net
The fault here lies with Excel.

Julian Day Counts start at noon, rather than midnight. 
Combine this with the timezone of your computer and you 
likely have your first day of error.

Excel also believes that February 29, 1900 is a valid 
day. This accounts for day two of your error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 10:01:29 2024 UTC