- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to subtract number of days from a date to get the previous date in R?
In our daily life, we might want to know what was the date before some number of days. This is also required in professional life, especially in those professions where we work on projects and have tight deadlines. To find the date before a certain number of days we can just use subtraction sign after reading the date with as.Date.
Examples
as.Date("2001-01-01")-30 [1] "2000-12-02" as.Date("2020-06-30")-30 [1] "2020-05-31" as.Date("2020-06-30")-50 [1] "2020-05-11" as.Date("2020-06-30")-100 [1] "2020-03-22" as.Date("2020-06-30")-120 [1] "2020-03-02" as.Date("2020-06-30")-15 [1] "2020-06-15" as.Date("2020-06-30")-45 [1] "2020-05-16" as.Date("2020-06-30")-40 [1] "2020-05-21" as.Date("2020-12-25")-20 [1] "2020-12-05" as.Date("2020-12-25")-300 [1] "2020-02-29" as.Date("2020-12-25")-125 [1] "2020-08-22" as.Date("2020-12-25")-80 [1] "2020-10-06"
We can also use / to read the dates as shown below −
as.Date("2020/12/25")-25 [1] "2020-11-30" as.Date("2020/12/25")-200 [1] "2020-06-08" as.Date("2020/12/25")-52 [1] "2020-11-03" as.Date("2020/12/25")-90 [1] "2020-09-26" as.Date("2020/12/25")-500 [1] "2019-08-13" as.Date("2020/12/25")-1000 [1] "2018-03-31"
- Related Articles
- How to subtract days from a date in JavaScript?
- Is there a way to subtract number of days from a date in MySQL?
- How to find the date after a number of days in R?
- Get the number of days between current date and date field?
- Subtract days from current date using Calendar.DATE in Java
- How to subtract date from today's date in JavaScript?
- How to add number of days to JavaScript Date?
- How to subtract Python timedelta from date in Python?
- How to get the records of the last two days from the current date in MySQL?
- How to subtract seconds from all the date records in a MySQL column?
- How to find the difference in number of days between two date columns of an R data frame?
- MySQL query to delete a DATE older than 30 days from another date?
- Java Program to subtract week from current date
- Java Program to subtract year from current date
- How to add number of business/working days or hours to a date in Excel?

Advertisements