Calendar`
Calendar`

DaysBetween

As of Version 10.0, calendar functionality is built into the Wolfram Language »

DaysBetween[{year1,month1,day1},{year2,month2,day2}]

gives the number of days between the dates {year1,month1,day1} and {year2,month2,day2}.

DaysBetween[{year1,month1,day1,hour1,minute1,second1},{year2,month2,day2,hour2,minute2,second2}]

gives the number of days between the given dates.

更多信息和选项

范例

打开所有单元关闭所有单元

基本范例  (7)

The number of days between consecutive days is 1:

The number of days between the same date is 0:

If the second date is earlier than the first date, then a negative result is returned:

John F. Kennedy's presidency is referred to as lasting 1000 days:

Hours, minutes, and seconds do not affect DaysBetween:

In the default (Western/American) calendar, 11 days were deleted in September 1752:

In the default (Western/American) calendar, 1752 had 355 days:

Options  (4)

Calendar  (4)

Catholic countries adopted the modern Gregorian calendar in 1582, while Britain and her colonies observed the Julian calendar until 1752. The Wolfram Language uses the British calendar, so Catholic date computations require the Gregorian option.

This computes the number of days Voltaire lived:

The Russian Orthodox Church has retained the Julian calendar. Their year 1900 was a leap year:

The standard Western year 1900 was not a leap year:

The Islamic year is much shorter than the Western year:

The length of the Jewish year varies greatly because there is a leap month:

Possible Issues  (2)

The Western calendar was modified from Julian to Gregorian for better accuracy. The change deleted 10 days in October 1582 in Catholic countries and deleted 11 days in September 1752 in Britain and her colonies. By default, the Wolfram Language applies the British (American) version. There is an issue for DaysBetween concerning dates after October 14, 1582 and before September 14, 1752. For British dates, the default gives the correct answer. For dates in Catholic countries, it is necessary to use the Gregorian option for Calendar.

This computes the number of days George Washington lived:

This computes the number of days Voltaire lived:

Because it is a solar and lunar calendar (the year follows the seasons, and the months keep track of the phases of the moon), the Jewish calendar has an extra leap month 7 times every 19 years. This leap month occurs in spring the month preceding Passover, so it is appropriate to count the Jewish months starting with Nisan, the month of Passover, as follows:

Since the Jewish year begins in the fall, this numeration of months will not always follow an increasing order; that is, later dates in the same year may have a smaller number for the month:

For this reason, DaysBetween will still work with the Calendar->Jewish option, but will not follow the same rules; for example, it will return a positive number even if the second date is lexicographically smaller (smaller in the canonical Wolfram Language ordering):