Open In App

Find the Difference Between Two Dates in R Programming - julian() Function

Last Updated : 22 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
In R programming, difference between two dates can be determined by using basic function julian() and passing date object as the parameter in the function. It ignores the leap-seconds.
Syntax: julian(x, origin) Parameters: x: represents date object origin: represents another date object from where difference has to be computed
Example 1: r
# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("2015-05-01")

# Difference between dates
julian(x, origin_date)
Output:
[1] 1875
attr(, "origin")
[1] "2015-05-01"
Example 2: r
# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("1920-06-18")

# Find difference between dates
julian(x, origin_date)
Output:
[1] 36525
attr(, "origin")
[1] "1920-06-18"

Next Article
Article Tags :

Similar Reads