Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 22 Jun, 2020

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:




# 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:




# 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"
My Personal Notes arrow_drop_up
Recommended Articles
Page :