OMG, PHP has to have a simple function that converts an integer representing a date since 1900 to month, day, year. If so, I can't find it.

I've got a CSV file from a spreadsheet that outputs the date as that integer value. All I want to do is read the file, convert that date integer to m,d,y and then display to a table on my site.

I've looked and looked and refuse to believe there isn't a simple way in PHP to do this conversion.

Anybody know of a way?

    Could you tell us exactly in what format the date is in that csv-file?

      With the incomplete information provided, I'm guessing that it's an Excel date. If so, this function should work:

      function xl_date_to_gregorian($format, $xl_date)
      {
          $greg_start = gregoriantojd(12, 31, 1899);
          return date($format, jdtounix($greg_start + $xl_date));
      }
      
      echo xl_date_to_gregorian('Y-m-d', '39088');

      Be sure to test; it might be off a day either way (or more 🙂 ).

        The only title of the scheme I've ever seen is "1900 Date System." It is used by Excel and other spreadsheets. VB also generates and handles it. It's the number of days since 1/1/1900. The integer returned would be like: 35785, which Excel and others would convert to 01/17/1996. (Example not accurate.)

        It looks like Installer is hot after it. Is our calendar the Georgian or Julian? A couple days off would be a problem. Is there a Julian equivelent function, should it be needed?

        Thanks for the help everybody, I was really starting to lose a lot of hair I can't afford to do without!

          The standard calendar is Gregorian. The Julian date is the number of days from a long time ago.

          I'm pretty sure my function will be accurate, but like I said, test it (like with some known dates from your csv file).

            It's offical, you're a genius. Thanks Installer. It's spot on.

            You've brought an end to several days search and endless would be accumulated hours of workaround. I owe you.

              Installer wrote:

              The Julian date is the number of days from a long time ago.

              Not to be confused with the Julian calendar (which was gradually dumped in Europe starting about five hundred years ago), the Julian Day format doesn't even refer to the same Julius 🙂

                Dumped also in the U.S., which is why George Washington was born something like eleven days before his birthday.

                  Julian date is year and days numbered from beginning of year, not to be confused with the Julian calendar which was dumped in the 17th century when they discovered that a year is actually 365 1/4 days, Gregorian calendar introduced the leap year to compensate.

                  Julian format is yyddd so today would be 07007. Used to use it on IBM mainframes in the 70s ( 1 MB was a big memory mainframe back then) Totally redundant now. Trust mickey soft to use something dumb like 1/1/1900 in Excel and VBA. I been writing VBA for 10 years and never even knew it was there. Go Figure.

                    From Wikipedia:

                    The Julian day or Julian day number (JDN) is the (integer) number of days that have elapsed since the initial epoch at noon Universal Time (UT) Monday, January 1, 4713 BC in the proleptic Julian calendar...The Julian date (JD) is a continuous count of days and fractions elapsed since the same initial epoch.

                      Ah yes Installer, serial time, yes I knew about that. Took one look, shuddered, and never thought about it again.

                        CVDATE (expression), in VB 4.0 Roger. "Expression" can be numeric or string.

                          Roger Ramjet wrote:

                          Took one look, shuddered, and never thought about it again.

                          Use it on a semiregular basis myself. Fits nicely into a double: 2454108.76590

                          Installer wrote:

                          Dumped also in the U.S.

                          In 1752, so it was dumped in North America before there was a U.S.

                            Write a Reply...