In the Wolfram Language, Now gives your current date and time.

Now

You can do computations on this, for example adding a week.

Now+LinguisticAssistant

Use (Key1[ctrl, =]) to enter a date in any standard format.

LinguisticAssistant

You can do arithmetic with dates, say, subtracting them to find how far apart they are.

Now-LinguisticAssistant

UnitConvert[Now-LinguisticAssistant,"Years"]

DayRange is the analog of Range for dates:

DayRange[Yesterday,Tomorrow]

DayName finds the day of the week for a particular date.

DayName[Today+LinguisticAssistant]

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).

MoonPhase[Now]

MoonPhase[LinguisticAssistant]

MoonPhase[LinguisticAssistant,"Icon"]

If you know both the date and a location on Earth, you can work out when the sun will rise and set.

Sunset[Here,Today]

Sunrise[Here,Tomorrow]-Sunrise[Here,Today]

Sunrise[Here,Tomorrow]-Sunrise[Here,Today]-LinguisticAssistant

Time zones are one of many subtleties. LocalTime gives the time in the time zone of a particular location.

LocalTime[LinguisticAssistant]

LocalTime[LinguisticAssistant]

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.

AirTemperatureData[Here,LinguisticAssistant]

If you provide a pair of dates, AirTemperatureData computes a time series of estimated temperatures between those dates.

AirTemperatureData[Here,{LinguisticAssistant,Now}]

DateListPlot is the analog of ListPlot for time series, where each value occurs at a particular date.

DateListPlot[AirTemperatureData[Here,{LinguisticAssistant,Now}]]

The plot shows that, not surprisingly, the temperature is higher during the day than at night.

As another example, let’s look at data that goes much further back in time. WordFrequencyData tells one how frequently a particular word occurs, say in a sample of books published in a given year. There’s a lot of history one can see by looking at how this changes over the years and centuries.

WordFrequencyData["automobile","TimeSeries"]

DateListPlot[WordFrequencyData["automobile","TimeSeries"]]

WordFrequencyData is set up to make it easy to compare frequencies of different words. Let’s see how “monarchy” and “democracy” have fared over the years. “Democracy” is definitely more popular now, but “monarchy” was more popular in the 1700s and 1800s.

DateListPlot[WordFrequencyData[{"monarchy","democracy"},"TimeSeries"]]

Compute how many days have elapsed since January 1, 1900. »

Compute what day of the week January 1, 2000 was. »

Find the date a hundred thousand days ago. »

Find the local time in Delhi. »

Find the length of daylight today by subtracting today’s sunrise from today’s sunset. »

Generate an icon for the current phase of the moon. »

Make a list of the numerical phase of the moon for each of the next 10 days. »

Generate a list of icons for the moon phases from today until 10 days from now. »

Compute the time today between sunrise in New York City and in London. »

Find the air temperature at the Eiffel Tower at noon yesterday. »

Plot the temperature at the Eiffel Tower over the past week. »

Find the difference in air temperatures between Los Angeles and New York City now. »

Plot the historical frequency of the word “groovy”. »

Compute how many weeks have elapsed since January 1, 1900. »

Compute the time between 3 pm today and sunset today. »

Generate an icon of the phase of the moon on August 29, 1959. »

Make a line plot of the numerical phase of the moon for each of the next 30 days. »

Make a Manipulate of the icon for the moon phase over the next 15 days. »

Show in a column the times of sunrise for 10 days, starting today. »

Plot together the historical frequencies of the words “science” and “technology”. »

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?

As far as you want. The Wolfram Language knows about historical calendar systems, and the history of time zones. It also has the data to accurately compute sunrise, etc. going back at least 1000 years.

Why are sunrise and sunset given only to the minute?

Because you can’t compute more accurately than that exactly when the sun will actually rise and set without knowing things like air temperature that affect the bending of light in the Earth’s atmosphere.

Where does the Wolfram Language get air temperature data from?

The worldwide network of weather stations, located at airports and other places. If you’ve got your own air temperature measuring device, you can connect it to the Wolfram Language through the Wolfram Data Drop (see Section 43).

What is a time series?

It’s 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[{{(Subscript[time, 1]),(Subscript[value, 1])},{(Subscript[time, 2]),(Subscript[value, 2])},...}]. 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 {{(Subscript[time, 1]),(Subscript[value, 1])},{(Subscript[time, 2]),(Subscript[value, 2])},...}.

Tech Notes