How to get the Julian Date in R

04.28.2021

The Julian date is the number of days since a specific date. In R, and many other languages, this is the number of days since January 1, 1970. This is a common method used in calendar applications. In this article, we will learn how to get the Julian date in R.

To get the Julian date, we can either use the as.integer method or the julian method.

today = Sys.Date()

as.integer(today)
# [1] 18741

The as.integer method simply converts our date to an integer which is the number of days since January 1, 1970. Let's see the julian method now.

today = Sys.Date()

jul = julian(today)
jul

# [1] 18741
# attr(,"origin")
# [1] "1970-01-01"

attr(jul, "origin")
# [1] 18741

The julian method returns a more complex object and stores the number of days in an attribute called "origin". We need to use another method attr to extract the value.