Lesson 5. How to Convert Day of Year to Year, Month, Day in R


Learning Objectives

After completing this tutorial, you will be able to:

What you need

You will need a computer with internet access to complete this lesson and the data for week 6 of the course.

Download Week 6 Data (~500 MB)

Landsat data are often saved using a date that includes the year and the day of year. You can quickly convert day of year to date as follows:

Here is our file name:

LC80340322016189-SC20170128091153

Looking at the name, we can see that the data were collected 2016-189. This references the 189th day of the year in 2016.

We can quickly convert this in R:

# note that R uses a 0 based index for dates only
# this means it starts counting at 0 rather than 1 when working with dates
as.Date(0, origin = "2016-01-01")
## [1] "2016-01-01"
# note that R uses a 0 based index
as.Date(1, origin = "2016-01-01")
## [1] "2016-01-02"

# figure out the date for day 189
as.Date(189, origin = "2016-01-01")
## [1] "2016-07-08"

Updated:

Leave a Comment