Calculate Time Difference between Dates in R Programming – difftime() Function

function in R Language is used to calculate time difference between dates in the required units like days, weeks, months, years, etc.**difftime()**

Syntax:difftime(date1, date2, units)

Parameters:date1, date2:Dates to calculate differenceunits:Days, weeks, months, etc.

**Example 1:**

`# R program to find time difference` ` ` `# Calling difftime() function` `difftime(` `"2020-5-16"` `, ` `"2020-1-15"` `, units ` `=` `"days"` `)` `difftime(` `"2020-5-16"` `, ` `"2020-1-15"` `, units ` `=` `"weeks"` `)` |

**Output:**

Time difference of 122 days Time difference of 17.42857 weeks

**Example 2:**

`# R program to find time difference` ` ` `# Calling difftime() function` `difftime(` `"2020-5-16"` `, ` `"2020-1-15"` `, units ` `=` `"hours"` `)` `difftime(` `"2020-5-16"` `, ` `"2020-1-15"` `, units ` `=` `"mins"` `)` |

**Output:**

Time difference of 2928 hours Time difference of 175680 mins

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.