Try now in the
Open Cloud »
(no sign-in required)

# Age in Days, Hours, etc.

Enter a date:

DateObject gives you an exact date that you can do computations with:

 In[1]:= XDateObject["November 16, 1998"]
 Out[1]=

It understands most common date formats:

 In[2]:= XDateObject["11/16/98"]
 Out[2]=
 In[3]:= XDateObject["16.11.98"]
 Out[3]=
 In[4]:= XDateObject["1998 Nov 16"]
 Out[4]=

 In[1]:= XDateObject["November 16, 1998"]
 Out[1]=

Run the code to compute the number of days from now back to a date. Try other dates:

Now gives you the date and time at the instant you run it:

 In[1]:= XNow
 Out[1]=

Subtract a date from Now to find the number of days back to the date:

 In[2]:= XNow -DateObject["November 16, 1998"]
 Out[2]=

 In[1]:= XNow - DateObject["November 16, 1998"]
 Out[1]=

Round to whole days. Try other dates:

Round rounds decimal numbers to integers:

 In[1]:= XRound[4.56]
 Out[1]=

Round a date computation to get an answer in whole days:

 In[2]:= XRound[Now - DateObject["November 16, 1998"]]
 Out[2]=

 In[1]:= XRound[Now - DateObject["November 16, 1998"]]
 Out[1]=

Convert to minutes. Try other dates, like your birthday (to find out how many minutes old you are):

UnitConvert converts between different units, like grams and pounds, or days and minutes.

This gives an answer in days:

 In[1]:= XRound[Now - DateObject["November 16, 1998"]]
 Out[1]=

Convert the result to minutes:

 In[2]:= XUnitConvert[Round[Now - DateObject["November 16, 1998"]], "Minutes"]
 Out[2]=

 In[1]:= XRound[UnitConvert[Now - DateObject["November 16, 1998"], "Minutes"]]
 Out[1]=

Spell out the result. Try other dates:

The result of a date calculation has both a value (the number) and a unit (min):

 In[1]:= XRound[UnitConvert[Now - DateObject["November 16, 1998"], "Minutes"]]
 Out[1]=

Use QuantityMagnitude to get just the value:

 In[2]:= XQuantityMagnitude[ Round[UnitConvert[Now - DateObject["November 16, 1998"], "Minutes"]]]
 Out[2]=

IntegerName gives the spelled-out names of numbers:

 In[3]:= XIntegerName[1234567]
 Out[3]=

Spell out the result of a date calculation:

 In[4]:= XIntegerName[ QuantityMagnitude[ Round[UnitConvert[Now - DateObject["November 16, 1998"], "Minutes"]]]]
 Out[4]=

 In[1]:= XIntegerName[ QuantityMagnitude[ Round[UnitConvert[Now - DateObject["November 16, 1998"], "Minutes"]]]]
 Out[1]=

Get the result in seconds. Try other units, like Hours, Weeks, or Months:

 In[1]:= XIntegerName[ QuantityMagnitude[ Round[UnitConvert[Now - DateObject["November 16, 1998"], "Seconds"]]]]
 Out[1]=

Share ItMake a website that tells you how many days old you are. Try making a site that tells you how many seconds old you are:

Deploy the days old calculation to make a website where you can enter a birthdate and find out how many days old you are:

 In[1]:= XCloudDeploy[FormFunction[{"birthdate" -> "Date"}, Round[Now - DateObject[#birthdate]] &, "PNG" ], Permissions -> "Public"]
 Out[1]=

Click the link in the output to visit the site.

Format the output more nicely using Row:

 In[2]:= XCloudDeploy[FormFunction[{"birthdate" -> "Date"}, Row[{"You are ", QuantityMagnitude[Round[Now - DateObject[#birthdate]]], " days old."}] &, "PNG" ], Permissions -> "Public"]
 Out[2]=

Make the text larger:

 In[3]:= XCloudDeploy[FormFunction[{"birthdate" -> "Date"}, Style[Row[{"You are ", QuantityMagnitude[Round[Now - DateObject[#birthdate]]], " days old."}], 48] &, "PNG" ], Permissions -> "Public"]
 Out[3]=

Share the link to the website by right-clicking the link in the output and choosing Copy Address. Paste the link into an email, tweet, or other message.

 In[1]:= XCloudDeploy[FormFunction[{"birthdate" -> "Date"}, Style[Row[{"You are ", QuantityMagnitude[Round[Now - DateObject[#birthdate]]], " days old."}], 48] &, "PNG" ], Permissions -> "Public"]
 Out[1]=