Converts serial Julian date into serial Excel date

View versions (1)

Interface

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

using namespace Units::Date;

This function converts the serial Julian date that we use as standard in the CodeCogs library into the single value that Excel uses to represent dates. It is the exact opposite of excelToJulian.

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 Excel date from a Julian number is:

ExcelDate = nDate - 2415019
(1)

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

Example 1

#include <stdio.h>
#include <codecogs/units/date/juliantoexcel.h>
#include <codecogs/units/date/date.h>
using namespace Units::Date;  
int main()
{
  printf("\nIf you type %d into Excel on a Mac, you get valentines day - don't forget!", julianToExcel(date("14 feb 2005"), true));    // 27076
  return 0;
}

Parameters

nDate
is the serial number that Excel uses to represent dates.
Mac
is a switch to identify which base date to use:
Blank
  • false: from Window Excel values using 1/1/1900.
  • true: from 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, default for Windows Excel. We can not generate the 29/2/1900 from any Julian values (because it really doesn't exist), however for earlier days we simply subtract one from the Excel values.

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

Interactive Calculator

nDate
Mac
Result