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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("2015-05-01")
  
# Difference between dates
julian(x, origin_date)

chevron_right


Output:

[1] 1875
attr(, "origin")
[1] "2015-05-01"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("1920-06-18")
  
# Find difference between dates
julian(x, origin_date)

chevron_right


Output:

[1] 36525
attr(, "origin")
[1] "1920-06-18"
My Personal Notes arrow_drop_up

Recommended Posts:


Blockchain Enthusiast

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.