CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

UnitsDate

date YMD

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 1.56
sub units 0.00
add a commercial licence to your cart
0
viewed 4187 times and licensed 119 times

Converts a serial Julian date into day, month and year values

Further Info Controller: CodeCogs  Contact Controller
+View version details
Contents hide toc
buy now     get GPL     add to cart

Interface

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

using namespace Units::Date;

void dateYMD (int nDate, int &year, int &month, int &day, calendar dateSystem=cal_Gregorian)
Converts a serial Julian date into day, month and year values
void dateYMD (const char* date, int &year, int &month, int &day, calendar dateSystem=cal_Gregorian, int century21st=30)
Extracts the components of a date (year, month, day) from a text string

Function Documentation

 
voiddateYMDintnDate
int& year
int& month
int& day
calendardateSystem = cal_Gregorian )
This function converts a serial Julian date, into a year, month and day, thereby performing the inverse of date. For the Gregorian calendar this conversion is achieved using:

{a=nDate + 32044} \hspace{20pt} {b=\frac{4a + 3}{146097}} \hspace{20pt}  {c=a- \frac{146097 b}{4}}
{d = \frac{4 c+3}{1461}} \hspace{20pt} {e = c - \frac{1461 d}{4}} \hspace{20pt} {m = \frac{5 e +2}{153}}

Day  = e - \frac{153 m +2}{5} + 1
Month= m + 3 - 12 \frac{m}{10}
Year = 100 b + d - 4800 + \frac{m}{10}

See:

The opposite of this function is date
Example 1:
#include <stdio.h>
#include <codecogs/units/date/dateymd.h>
using namespace Units::Date;
 
int main()
{
  int d,m,y;
  dateYMD(36922, y, m, d);
  printf("\n The Gregorian Date is: day=%d month=%d year=%d", d, m, y);   // 6 May 1987

dateYMD(36922, y, m, d, cal_Julian); printf("\n The Julian Date is: day=%d month=%d year=%d", d, m, y); // 23 April 1987 return 0; }

References:
Tondering, C. 2003. http://www.tondering.dk/claus/cal/node3.html
Parameters:
nDateis the number of days from 24 November 4714 BC - otherwise known as the Julian Period (also 1 January 4713BC in the Julian Calendar).
yearis a location (passed by reference) into which is placed the Year.
monthis a location (passed by reference) into which is placed the Month.
dayis a location (passed by reference) into which is placed the Day.
dateSystemselects which date system the result will be converted into (see constants):
Authors:
Will Bateman (Sep 2004)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

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


 
voiddateYMDconst char*date
int& year
int& month
int& day
calendardateSystem = cal_Gregorian
intcentury21st = 30 )
This function uses a number of rules to work out the most likely date, returning the individual elements (Year, Month and Day) of the date. Unlike the Excel version this function is extremely forgiving, it will therefore interpret most date forms and will not return an error.
Todo:
Anyone wanting a challenge can try optimising this function and including an option to allow alternative defaults.
Example 2:
This example is intended to illustrates the type of dates that can be processed, rather than to being functional (see units/date for a further examples).
#include <stdio.h>
#include <codecogs/units/date/date.h>
using namespace Units::Date;
 
void main()
{
  int d,m,y;
  dateYMD("3245/4 20", y,m,d, cal_Excel);               // 20 April 3245
  dateYMD("4February 4", y,m,d);                        // 4 February 0004
  dateYMD("40 mar 1664", y,m,d);                        // 40 March 1664 !!!
  dateYMD("24-10/40", y,m,d, cal_Excel);                // 24 October 1940
  dateYMD("12@31@4", y,m,d);                            // 12 April 0031
  dateYMD("16 5 march", y,m,d, cal_Excel);              // 16 March 2005
  dateYMD("jansomerubbish4 10", y,m,d, cal_Excel, 10);  // 4 January 2010
}

Note:
This function can extract an illegal date, e.g. dateYMD("31 February 2004",y,m,d) will return the 31st February 2004. To be confident of having a legitimate date, use date instead, e.g. date("31 February 2004") will return the 2 March 2004.
Parameters:
dateis a text string containing a date, with the following attributes:
yearis a location (passed by reference) into which is placed the Year.
monthis a location (passed by reference) into which is placed the Month.
dayis a location (passed by reference) into which is placed the Day.
dateSystemonly has an effect if equal to cal_Excel, when it adds 1900 to any dates below 1900 (see constants).
century21stdefines the two digit years that occurs in the 21st century, as opposed to the 20th Century. In any DateSystem not equal to cal_Excel 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 cal_Excel this variable is set once for all sheets via the options panel).
Authors:
Will Bateman (Sep 2004)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

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


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2010-03-10 00:16:45

Valid CSS!   Valid XHTML 1.0 Transitional