Forgotten Password?

Or login with:

  • Facebook
  • Google
  • Yahoo
get GPL
this unit 2.00
sub units 1.87


viewed 11046 times and licensed 314 times
Calculates the serial date from the parameters \b day, \b month and \b year. Excel: DATE
Controller: CodeCogs






This function converts a date (with day, month and year specified separately) into a single serial value known as the Julian date (sometimes also referred to as the Julian number). It is a single number that represents the number of days between the date specified and the 24 November 4714BC (or 1 January 4713 BC in the Julian calendar). Therefore the 24 November 4714BC corresponds to 0 in the serial Julian date form. Dates in this form are extremely easy to manipulate, for example:

To add seven days to a serial date you merely add 7,
int nextweek=date("25/Feb/04") + 7;                       // the same as date("3/March/04")
To find the number of days between two dates you subtract one from the other,
int milleniumdays=date("10/10/2004")-date("1 Jan 2000");  // 1744 days

The serial Julian date is one of the most recognised standards for collapsing any date into a single number and is the standard that has been adopted for most calculations.

However, any point in time can also be represented by a variety of different date styles or calendars. We currently recognise these standards (though we hope to expand this range):
cal_JulianThe Julian calendar was introduced in 45BC and was commonly used until the late 16 century. The Julian calendar is 365 1/4 days long, which gives an error of 1 day in every 128 years.
cal_GregorianThe Gregorian calendar was first introduced in 1582 by predominantly Catholic countries, to rectify the error in the Julian calendar. This change occurred on the 4th October 1582, with 10 days being lost, such that 15th October was the next day. Over the next 500 years, the majority of the world has adopted this standard, the main exceptions being the Greek and Russian Orthodox churches, which still use the Julian calendar.
cal_ExcelThe Excel date system isn't an official date system, but we use it here to provide compatibility to Microsoft Excel referring to a system that starts on 1 Jan 1900, such that years values below 1900, are assumed to be 1900+year. e.g. 20 is 1920; 110 is 2010. Excel on the Mac doesn't allow value prior to 1 January 1904, however for all practical purposes this limitation can be ignored. Aside from this peculiarity, both Excel date systems are identical to the Gregorian system.


calendarDateSystem = cal_Gregorian )
Returns the serial Julian date, the number of days between the specified date (Year, Month and Day) and the 24 November 4714BC (in the Gregorian Calendar). The calculation of the serial Julian date is: where all divisions are an integer divisions (rounding down). Clearly solution perfectly accounts for all leap years and varying month lengths to produce a unique serial number for each and every day. The limitation are bound by the numerical accuracy of your computer.


The opposite function is dateYMD


Tondering, C. 2003.

Example 1

To compute the serial number for 1st February 2005
int gregorianNo  =date(2005, 2, 1, cal_Gregorian);
  int JulianNo     =date(2005, 2, 1, cal_Julian);
  int ExcelNo      =date(105,  2, 1, cal_Excel);


Yearcan be any integer greater than 4800 BC. The format to achieve this varies with the DateSystem in use:
Monthcontains the month of the year. This value must be within the range -9 to 14 (inclusive), though value outside the range 1-12 will be divided by by 12, such that the Year incremented by the quotient and the Month set to the remainder. For example date(2000,13,1) is equivalent to date(2001,1,1).
Daycontains the day of the month. If day is greater than the number of days in the month specified, then the difference cascades through the first days of subsequent months. For example date(2000,1,32) is equivalent to date(2000,2,1).
DateSystemselects which date system should be used (see constants):


Will Bateman (Sep 2004)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


intdateconst char*Date
calendarDateSystem = cal_Gregorian
intCentury21st = 30 )
This function uses dateYMD to extract the most likely date elements from Date. This is converted into a Julian Date (number of days) using date.


  • Anyone wanting a challenge can try optimising this function and including an option to allow alternative defaults.
  • Write a strict date function, where the user specifies the format and the function complains when the syntax is not suitable.

Example 2

#include <stdio.h>
#include <codecogs/units/date/date.h>
using namespace Units::Date;
int main()
  // Using Gregorian calendar with cal_Excel modification
  printf("\n Julian date=%d",date("2232/4 20", cal_Excel));    // 119910  = 20 April 2232
  printf("\n Julian date=%d",date("4February 4", cal_Excel));  // 36559   = 4 February 2004
  printf("\n Julian date=%d",date("30 feb 1974", cal_Excel));  // 25628   = 2 march 1974
  printf("\n Julian date=%d",date("22%12&40", cal_Excel));     // 13505   = 22 December 1940
  printf("\n Julian date=%d",date("12|31#4", cal_Excel));      // 9963    = 12 April 1931
  printf("\n Julian date=%d",date("12 4 march", cal_Excel));   // 36596   = 12 March 2004
  printf("\n Julian date=%d",date("deCeMbeR4 80", cal_Excel)); // 28097   = 4 December 1980
  printf("\n Julian date=%d",date("jan$80 4", cal_Excel));     // 27762   = 4 January 1980
  printf("\n Julian date=%d",date("FEBR+4", cal_Excel));       // 36559   = 4 February 2004
  // Using the Gregorian calendar
  printf("\n Julian date=%d",date("jul/1100/4"));              // 2123011 = 4 July 1100
  printf("\n Julian date=%d",date("12FEBR-354"));              // 1850398 = 12 February 354
  // Using the Julian calendar
  printf("\n Julian date=%d",date("June 4 56", cal_Julian));   // 36596   = 12 March 2004
  printf("\n Julian date=%d",date("sep 2 3", cal_Julian));     // 28097   = 4 December 1980
  return 0;


Dateis a text string containing a date, with the following attributes (also see dateYMD):.
DateSystemselects which date system should be used (see constants):
Century21stdefines the two digit years that occur in the 21st century, as opposed to the 20th Century. In the Julian DateSystem this parameter is ignored, otherwise the 2000 is added to any year values below Century21st, while 1900 is added to years equal to and above Century21st (Within Excel this variable is set once for all sheets via the options panel).


Will Bateman (Sep 2004)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Last Modified: 19 Dec 11 @ 00:18     Page Rendered: 2022-03-14 15:26:13