19 Dates and Times
In the Wolfram Language, Now gives your current date and time.
 In[1]:=
 Out[1]=
Add a week to the current date and time:
 In[2]:=
 Out[2]=
Enter a date:
 In[3]:=
 Out[3]=
InputForm shows that internally a date is a DateObject[ ...]. You can always enter dates directly in this form.
Find the internal representation of a date:
 In[4]:=
 Out[4]=
Subtract two dates:
 In[5]:=
 Out[5]=
 In[6]:=
 Out[6]=
DayRange is the analog of Range for dates:
 In[7]:=
 Out[7]=
DayName finds the day of the week for a particular date.
Compute the day of the week 45 days from now:
 In[8]:=
 Out[8]=
Once you know a date, there are lots of things you can compute. For example, MoonPhase gives the phase of the moon (or, more accurately, the fraction of the Moon that is illuminated when seen from the Earth).
Compute the phase of the moon now:
 In[9]:=
 Out[9]=
Compute the phase of the moon on a certain date:
 In[10]:=
 Out[10]=
Generate an icon for the phase of the moon:
 In[11]:=
 Out[11]=
If you know both the date and a location on Earth, you can work out when the sun will rise and set.
 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=
Time zones are one of many subtleties. LocalTime gives the time in the time zone of a particular location.
 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
Among the many areas where the Wolfram Language has extensive data is weather. The function AirTemperatureData uses this data to give the historical air temperature at a particular time and place.
Find the air temperature here at 6 pm yesterday:
 In[16]:=
 Out[16]=
If you provide a pair of dates, AirTemperatureData computes a time series of estimated temperatures between those dates.
Give a time series of air temperature measurements from a week ago until now:
 In[17]:=
 Out[17]=
DateListPlot is the analog of ListPlot for time series, where each value occurs at a particular date.
Plot the list of air temperature measurements:
 In[18]:=
 Out[18]=
Vocabulary
19.1Compute how many days have elapsed since January 1, 1900. »
Sample expected output:
 Out[]=
19.2Compute what day of the week January 1, 2000 was. »
Sample expected output:
 Out[]=
19.3Find the date a hundred thousand days ago. »
Sample expected output:
 Out[]=
19.4Find the local time in Delhi. »
Sample expected output:
 Out[]=
19.5Find the length of daylight today by subtracting todays sunrise from todays sunset. »
Sample expected output:
 Out[]=
19.6Generate an icon for the current phase of the moon. »
Sample expected output:
 Out[]=
19.7Make a list of the numerical phase of the moon for each of the next 10 days. »
Sample expected output:
 Out[]=
19.8Generate a list of icons for the moon phases from today until 10 days from now. »
Sample expected output:
 Out[]=
19.9Compute the time today between sunrise in New York City and in London. »
Sample expected output:
 Out[]=
19.10Find the air temperature at the Eiffel Tower at noon yesterday. »
Sample expected output:
 Out[]=
19.11Plot the temperature at the Eiffel Tower over the past week. »
Sample expected output:
 Out[]=
19.12Find the difference in air temperatures between Los Angeles and New York City now. »
Sample expected output:
 Out[]=
+19.1Compute how many weeks have elapsed since January 1, 1900. »
Sample expected output:
 Out[]=
+19.2Compute the time between 3 pm today and sunset today. »
Sample expected output:
 Out[]=
+19.3Generate an icon of the phase of the moon on August 29, 1959. »
Sample expected output:
 Out[]=
+19.4Make a line plot of the numerical phase of the moon for each of the next 30 days. »
Sample expected output:
 Out[]=
+19.5Make a Manipulate of the icon for the moon phase over the next 15 days. »
Sample expected output:
 Out[]=
+19.6Show in a column the times of sunrise for 10 days, starting today. »
Sample expected output:
 Out[]=
Q&A
How can I get a date as a string?
Use DateString[date]. There are many options for the format of the string. For example, DateString[date, "DateShort"] uses short day and month names.
How can I extract the month or some other element from a date?
Use DateValue. DateValue[date, "Month"] gives the month number, DateValue[date, "MonthName"] gives the month name, etc.
How far in the past can dates be in the Wolfram Language?
Where does the Wolfram Language get air temperature data from?
What is a time series?
Its a way of specifying the values of something at a series of times. You can enter a time series in the Wolfram Language as TimeSeries[{{time1, value1}, {time2, value2}, ...}]. The Wolfram Language lets you do arithmetic and many other operations with time series.
What does DateListPlot do?
It plots values against times or dates. The values can be given in a TimeSeries[...] or in a list of the form {{time1, value1}, {time2, value2}, ...}.
More to Explore