Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Data Manipulation > Date & Time >

DateDifference

DateDifference[date1, date2]
gives the number of days from date1 to date2.
DateDifference[date1, date2, "unit"]
gives the difference between date1 and date2 in the specified unit.
DateDifference[date1, date2, {"unit1", "unit2", ...}]
gives the difference as a list with elements corresponding to the successive "uniti".
  • 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 ("Jan. 1, 2000")
{y,m,d,h,m,s}precise time
timeabsolute time specification
  • Possible units are "Year", "Quarter", "Month", "Week", "Day", "Hour", "Minute", "Second".
  • {y, m, d} is taken to be equivalent to {y, m, d, 0, 0, 0}, etc.
  • DateDifference[date2] gives the fractional number of days from the current time until date2.
Give the number of days between January 1 and July 4:
Use dates specified in {y, m, d} form:
Find a date difference in units of weeks:
If the second date is before the first, the date difference is negative:
Give the number of days between January 1 and July 4:
In[1]:=
Click for copyable input
Out[1]=
 
Use dates specified in {y, m, d} 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]=
Give dates in any format supported by DateString:
List and string date specifications can be mixed:
DateDifference can use times given in {y, m, d, h, m, s} format:
Find the number of hours between two dates:
Find the number of years between two dates:
Find the difference between two dates in months and days:
Find the number of years, months and days since the beginning of the year 2000:
DatePlus adds time units to dates, while DateDifference computes units between dates:
The inverse relationship:
Date strings can be ambiguous:
Use DateList to disambiguate between different interpretations:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team