Outputting pretty dates and times
An easy way to output dates is to use the stamp()
function in lubridate
. stamp()
takes a string which should be an example of how the date should be formatted, and returns a function that can be used to format dates.
In this exercise you'll practice outputting today()
in a nice way.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
- Create a
stamp()
based on the string"Saturday, Jan 1, 2000"
. - Print
date_stamp
. Notice it is a function. - Pass
today()
todate_stamp
to format today's date. - Now output today's date in American style
MM/DD/YYYY
. - Finally, use stamp based on the
finished
string I've put in your workspace to formattoday()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a stamp based on "Saturday, Jan 1, 2000"
date_stamp <- stamp(___)
# Print date_stamp
# Call date_stamp on today()
___(today())
# Create and call a stamp based on "12/31/1999"
stamp(___)(today())
# Use string finished for stamp()
stamp(___)(today())