DateDifference

DateDifference[date1, date2]
gives the number of days from to .

DateDifference[date1, date2, "unit"]
gives the difference between and in the specified unit.

DateDifference[date1, date2, {"unit1", "unit2", ...}]
gives the difference as a list with elements corresponding to the successive .

Details and OptionsDetails and Options

  • Dates can be specified in the following forms:
  • {y,m,d}year, month, day
    {y,m}the first day of the specified month
    {y}January 1 of the year y
    "string"date as a string ()
    {y,m,d,h,m,s}precise time
    timeabsolute time specification
  • Possible units are , , , , , , , .
  • is taken to be equivalent to etc.
  • DateDifference takes the following option:
  • DayCountConvention"ActualActual"counting convention by which the difference is computed
  • DateDifference enumerated in days follows the day count convention, regardless of the magnitude of the difference.
  • DateDifference[date2] gives the fractional number of days from the current time until .

ExamplesExamplesopen allclose all

Basic Examples (4)Basic Examples (4)

Give the number of days between January 1 and July 4:

In[1]:=
Click for copyable input
Out[1]=

Use dates specified in form:

In[1]:=
Click for copyable input
Out[1]=

Find a date difference in units of weeks:

In[1]:=
Click for copyable input
Out[1]=

If the second date is before the first, the date difference is negative:

In[1]:=
Click for copyable input
Out[1]=
New in 6 | Last modified in 9
New to Mathematica? Find your learning path »
Have a question? Ask support »