
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Date After a Number of Days in R
In our daily life, often we want to know what will be date after 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 after a number a certain number of days we can just use plus sign after reading the date with as.Date.
Example
> as.Date("2001-01-01")+30 [1] "2001-01-31" > as.Date("2020-06-30")+30 [1] "2020-07-30" > as.Date("2020-06-30")+50 [1] "2020-08-19" > as.Date("2020-06-30")+100 [1] "2020-10-08" > as.Date("2020-06-30")+120 [1] "2020-10-28" > as.Date("2020-06-30")+15 [1] "2020-07-15" > as.Date("2020-06-30")+45 [1] "2020-08-14" > as.Date("2020-06-30")+40 [1] "2020-08-09" > as.Date("2020-12-25")+20 [1] "2021-01-14" > as.Date("2020-12-25")+300 [1] "2021-10-21" > as.Date("2020-12-25")+125 [1] "2021-04-29" > as.Date("2020-12-25")+80 [1] "2021-03-15"
We can also use / to read the dates as shown below −
> as.Date("2020/12/25")+25 [1] "2021-01-19" > as.Date("2020/12/25")+200 [1] "2021-07-13" > as.Date("2020/12/25")+52 [1] "2021-02-15" > as.Date("2020/12/25")+90 [1] "2021-03-25" > as.Date("2020/12/25")+500 [1] "2022-05-09" > as.Date("2020/12/25")+1000 [1] "2023-09-21"
Advertisements