Find number of months between two dates in R Last Updated : 07 Sep, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to Find the number of months between two dates in the R programming language. Example: Input: Date_1 = 2020/02/21 Date_2 = 2020/03/21 Output: 1 Explanation: In Date_1 and Date_2 have only one difference in month. Here we will use seq() function to get the result. This function is used to create a sequence of elements in a Vector. It takes the length and difference between values as optional argument. Syntax: length(seq(from=date_1, to=date_2, by='month')) -1 Where: seq is function generates a sequence of numbers, from is starting date, to is ending date. Example 1: In the below example, we are storing two dates in two different variables and by using length(seq(from=date_1, to=date_2, by='month')) we are finding a number of months between these two dates. R # creating date_1 variable and storing date in it. date_1<-as.Date("2020-08-10") # creating date_2 variable and storing date in it. date_2<-as.Date("2020-10-10") # Here first date will start from 2020-08-10 and # end by 2020-10-10.Here increment is done by month. # This three dates will be generated as we used # seq and this dates will be stored in a. a = seq(from = date_1, to = date_2, by = 'month')) # Here we are finding length of a and we are subtracting # 1 because we dont need to include current month. length(a)-1 Output: 2 Example 2: Checking with different dates. R # creating date_1 variable and storing date in it. date_1<-as.Date("2020-01-23") # creating date_2 variable and storing date in it. date_2<-as.Date("2020-9-25") # Here first date will start from 2020-01-23 # and end by 2020-9-25.Here increment is done # by month.This three dates will be generated # as we used seq and this dates will be stored in a. a=seq(from = date_1, to = date_2, by = 'month')) # Here we are finding length of a and we are # subtracting 1 because we dont need to include # current month. length(a)-1 Output: 8 Comment More infoAdvertise with us Next Article Find number of months between two dates in R B bhagiradhrayini25 Follow Improve Article Tags : R Language R Vector-Function Similar Reads Program to count number of days between two given months Write a program to count the number of days between two given months (including start as well as end month). Assume the number of days in February as 28. Examples: Input: startMonth = "january", endMonth ="january"Output: 31Explanation: January has 31 days. Input: startMonth = "january", endMonth = 6 min read How to Iterate over months between two dates in Python? In this article, we will discuss how to iterate over months between two dates using Python. We can iterate over months between two dates using timedelta and rrule methods. Method 1: Iteration using timedeltatimedelta() is used for calculating differences in dates and also can be used for date manipu 2 min read How to calculate number of days between two dates in R ? 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 RDates 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 dat 2 min read How to Get Number of Days in Current Month in PHP? This article will show you how to get the number of days in the current month in PHP. In PHP, you may need to find the number of days in the current month for various purposes, such as generating a calendar or performing date calculations. There are three approaches to get the number of days in the 3 min read Program to find the number of days in a given month Write a program to find the number of days in a given month. We are given name of a month in lowercase letters, so print the number of days in the month. Note: For February, consider the number of days as 28. Examples: Input: month = "january"Output: 31Explanation: January has 31 days. Input: month 3 min read Like