Main Content

juliandate

Convert MATLAB datetime to Julian date

Description

example

jd = juliandate(t) returns the Julian dates equivalent to the datetime values in t.

  • If the time zone of t is not specified, then juliandate treats the times in t as UTC times. This interpretation might differ from your treatment of "unzoned" datetime arrays in other contexts. For example, you might think of datetime("now") as returning your local time. However, juliandate interprets it as a UTC time.

  • If the time zone of t is specified, then juliandate uses the offset for the time zone to compute Julian dates with respect to UTC.

  • juliandate ignores leap seconds unless the time zone of t is UTCLeapSeconds.

The best practice is to specify the time zone of t before calling juliandate.

jd = juliandate(t,dateType) returns the type of Julian dates specified by dateType. For example, you can convert datetime values to modified Julian dates.

Examples

collapse all

Create datetime values and convert them to the equivalent Julian dates. Show the differences in Julian dates between zoned and unzoned datetime values. The best practice is to specify a time zone for a datetime array before calling juliandate.

Create a datetime array and specify its time zone.

tStrings = ["2022-02-01 10:05:24", ...
            "2022-04-01 10:05:24", ...
            "2022-10-01 10:05:24", ...
            "2022-12-01 10:05:24"];
t = datetime(tStrings);
t.TimeZone = 'America/New_York'
t = 1x4 datetime
Columns 1 through 3

   01-Feb-2022 10:05:24   01-Apr-2022 10:05:24   01-Oct-2022 10:05:24

Column 4

   01-Dec-2022 10:05:24

Convert t1 to the equivalent Julian dates. juliandate accounts for the time zone offset with respect to UTC when it calculates Julian dates. In this example, the shifts to and from daylight saving time that occur in March and November of 2022 change the time zone offset with respect to UTC. Therefore the fractional parts of jd(1) and jd(4) differ from the fractional parts of jd(2) and jd(3).

format longG
jd = juliandate(t)
jd = 1×4

             2459612.12875          2459671.08708333          2459854.08708333             2459915.12875

Create a copy of t that has no time zone. Convert it to the equivalent Julian dates. juliandate treats the times in tUnzoned as UTC times, with no time zone offset.

tUnzoned = t;
tUnzoned.TimeZone = '';
jdUnzoned = juliandate(tUnzoned)
jdUnzoned = 1×4

          2459611.92041667          2459670.92041667          2459853.92041667          2459914.92041667

Show the differences between jdUnzoned and jd. The differences are equal to the time offset, in days, between times in tUnzoned (which juliandate interprets as UTC times) and the times in t (which are in the America/New_York time zone).

jdUnzoned - jd
ans = 1×4

        -0.208333333488554        -0.166666666511446        -0.166666666511446        -0.208333333488554

Input Arguments

collapse all

Input date and time, specified as a datetime array.

Type of Julian date values, specified as either "juliandate" or "modifiedjuliandate".

  • If dateType is "juliandate", then juliandate converts the datetime values in t to the equivalent Julian dates. A Julian date is the number of days and fractional days since noon on November 24, 4714 BCE in the proleptic Gregorian calendar, or January 1, 4713 BCE in the proleptic Julian calendar.

  • If dateType is "modifiedjuliandate", then juliandate converts the datetime values in t to the equivalent modified Julian dates. A modified Julian date is the number of days and fractional days since November 17, 1858 00:00:00.

More About

collapse all

Julian dates

A Julian date is the number of days and fractional days since noon on November 24, 4714 BCE in the proleptic Gregorian calendar, or January 1, 4713 BCE in the proleptic Julian calendar.

Extended Capabilities

Version History

Introduced in R2014b