How to Get the Day of a Date Object in R (Example Code)

In this tutorial you’ll learn how to return only the day of a Date object in R.

Creation of Example Data

my_date <- as.Date(c("2021-06-13",    # Creating vector of Date objects
                     "2025-09-05",
                     "2016-12-11"))
my_date                               # Showing date vector in RStudio console
# "2021-06-13" "2025-09-05" "2016-12-11"

Example: Applying format Function to Extract Day from Date

format(my_date, format = "%d")        # Using format function
# "13" "05" "11"

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top