Routines (alphabetical) > Routines: G > GREG2JUL

# GREG2JUL

The GREG2JUL function calculates the Julian Date (which begins at noon) for the specified Gregorian date. This is the inverse of the JUL2GREG procedure.

Notes

- The GREG2JUL function uses the proleptic Gregorian date, which is produced by extending the Gregorian calendar backwards to dates preceeding its introduction in 1582. In the proleptic Gregorian calendar, there are no missing days in October 1582, every 4 years is a leap year, except if the year ends in a "00" then it is not a leap year, unless it is also divisible by 400 (in which case it is a leap year).
- There is no year 0 in the calendar as defined by IDL. Instead,year 1 CE is immediately preceeded by year 1 BCE. This means that leap years are offset by 1. For example, -5, -9, -13, etc. are all leap years, -101 is not a leap year (following the rule for "00" years), but -401 is a leap year.
- The proleptic Gregorian calendar is usually required for information exchange between international partners, as defined by ISO 8601:2004 (clause 3.2.1). The proleptic Gregorian calendar is not used by astronomers, who instead use the Julian Day Number, as given by the JULDAY function.
- The GREG2JUL function should only be used with the JUL2GREG procedure. Similarly, the JULDAY function should only be used with CALDAT. For dates between 1 Jan CE and 15 Oct 1582 the two calendar systems differ by up to 10 days. For dates on or after 15 Oct 1582 the two calendar systems are identical.
- A small offset is added to the returned Julian date to eliminate roundoff errors when calculating the day fraction from hours, minutes, seconds. This offset is given by the larger of EPS and EPS*Julian, where Julian is the integer portion of the Julian date, and EPS is the EPS field from MACHAR (using double precision). For typical Julian dates, this offset is approximately 6x10–10 (which corresponds to 5x10–5 seconds). This offset ensures that if the Julian date is converted back to hour, minute, and second, then the hour, minute, and second will have the same integer values as were originally input.
- Calendar dates must be in the range 24 Oct 4801 BCE to 31 Dec 5000000, which corresponds to Julian values -31776 and 1827933925, respectively.
- This routine is written in the IDL language. Its source code can be found in the file `greg2jul.pro` in the `lib` subdirectory of the IDL distribution.

## Examples

Print out all of the "special" leap days between 1 C.E. and the present:

PRINT, GREG2JUL(2,29,400), GREG2JUL(2,29,800), GREG2JUL(2,29,1200), $

GREG2JUL(2,29,1600), GREG2JUL(2,29,2000)

IDL prints:

1867216 2013313 2159410 2305507 2451604

Using arrays, this can also be calculated as follows:

PRINT, GREG2JUL(2,29,[400,800,1200,1600,2000])

As another example, print the number of days between 17 January 1850 and 1 January 850:

PRINT, GREG2JUL(1,17,1850) - GREG2JUL(1,1,850)

IDL prints:

365258

## Syntax

Result = GREG2JUL(Month, Day, Year, Hour, Minute, Second)

## Return Value

Result is of type double-precision if Hour, Minute, or Second is specified, otherwise Result is of type long integer. If all arguments are scalars, the function returns a scalar. If all arguments are arrays, the function matches up the corresponding elements of the arrays, returning an array with the same dimensions as the smallest array. If the inputs contain both scalars and arrays, the function uses the scalar value with each element of the arrays, and returns an array with the same dimensions as the smallest input array.

## Arguments

If no arguments are given then the Julian date corresponding to the current system time is returned.

### Month

Number of the month (1 = January, ..., 12 = December). Month can be either a scalar or an array.

### Day

Number of the day of the month (1-31). Day can be either a scalar or an array.

### Year

Number of the year (e.g., 1994). Year can be either a scalar or an array.

### Hour

Number of the hour of the day (0-23). Hour can be either a scalar or an array.

### Minute

Number of the minute of the hour (0-59). Minute can be either a scalar or an array.

### Second

Number of the second of the minute (0-59). Second can be either a scalar or an array.

## Version History

8.2.1 | Introduced

## See Also

CALDAT, JUL2GREG, JULDAY, SYSTIME,Date/Time Data