CodeCogs
HomeForumsCart
Login



Forgotten Password?

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 1.87
sub units 0.00
+
0
UnitsDate

date YMD

viewed 4443 times and licensed 288 times
Converts a serial Julian date into day, month and year values
Controller: CodeCogs

Dependents

Info

Interface

C++

DateYMD

 
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:

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

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.


DateYMD

 
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

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: 18 Oct 07 @ 17:07     Page Rendered: 2022-03-14 15:12:05