Converts serial Excel date into serial Julian date

View versions (1)

Interface

#include <codecogs/units/date/exceltojulian.h>

using namespace Units::Date;

This function converts the serial numbers that Excel use to represent dates, into a serial Julian number, which is standard adopted by the CodeCogs library. It is the exact opposite of julianToExcel.

Excel only understands the Gregorian date system, but for added confusion Microsoft have chosen to present dates differently under the Windows and Apple OSX operating systems (though you can change this default behaviour):

  • the Windows standard: starts on the 1 January 1900, which is represented by 1.
  • the Mac standard (Apple's OSX): starts on 1 January 1904, which is represented by 0.

On a Windows platform the calculation to get the serial Julian date is:

nDate = ExcelDate + 2415020
(1)

On a Mac (OSX) you add an extra 365*4 + 1

Example 1

#include <stdio.h>
#include <codecogs/units/date/exceltojulian.h>
#include <codecogs/units/date/dateymd.h>
using namespace Units::Date;
  
int main()
{
    for(int i=5555;i<5560;i++)
    {
      int y,m,d;
      dateYMD(excelToJulian(i),y,m,d);
      printf("\nWindows Excel use %d to represent %d-%d-%d",i, d,m,y);
    }
  return 0;
}

Output:

Windows Excel use 5555 to represent 17-3-1915
Windows Excel use 5556 to represent 18-3-1915
Windows Excel use 5557 to represent 19-3-1915
Windows Excel use 5558 to represent 20-3-1915
Windows Excel use 5559 to represent 21-3-1915

Parameters

ExcelDate
is the serial number that Excel uses to represent dates.
Mac
is a switch to identify which base date to use:
Blank
  • false: to Window Excel values using 1/1/1900.
  • true: to Mac Excel values using 1/1/1904.

Unfortunately Microsoft made a mistake, so they think 29/2/1900 exists - but 1900 isn't a leap year!! This clearly only has an impact in the 1900 date system, standard on Windows Excel. Therefore to handle this error, we simply assume an Excel value of 60 to correspond to 1/3/1900. While values below 60 are incremented by 1.

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

ExcelDate
Mac
Result