VOOZH about

URL: https://www.geeksforgeeks.org/r-language/how-to-calculate-number-of-days-between-two-dates-in-r/

⇱ How to calculate number of days between two dates in R ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to calculate number of days between two dates in R ?

Last Updated : 23 Jul, 2025

In this article, we will discuss how to Find the number of days between two dates in the R programming language

Working with Dates in R

Dates play a crucial role in data analysis, and figuring out the time difference between two dates is a typical job. Calculating the number of days between two dates in R is simple owing to built-in functions and date manipulation packages. In this post, we'll look at many methods for calculating the number of days between two dates in R.

Example:

Input:
 Date_1 = 2020/03/21
 Date_2 = 2020/03/22Output: 1Explanation:In Date_1 and Date_2 have only one day difference. So output will be 1.

Here we will use the seq() function to get the result. This function is used to create a sequence of elements in a Vector. To get the number of days length() function is employed with seq() as an argument.

Syntax: length(seq(from=date_1, to=date_2, by='day')) -1

Parameter:

  • seq is function generates a sequence of numbers.
  • from is starting date.
  • to is ending date.
  • by is step, increment.

Method 1: Using the seq() function

Output:

[1] 1

Method 2: Using subtraction

Output:

Time difference of 16 days

Method 3: Using difftime() function

Output:

[1] 16

Method 4: Using bizdays package in R

Output:

[1] 30
Comment
Article Tags:

Explore