Given a date and a positive integer x. The task is to find date after adding x days to the given date
Input : d1 = 14, m1 = 5, y1 = 2017 Days to be added x = 10 Output : d2 = 24, m2 = 5, y2 = 2017 Input : d1 = 14, m1 = 3, y1 = 2015 Days to be added x = 466 Output : d2 = 14, m2 = 3, y2 = 2016
1) Let given date be d1, m1 and y1. Find offset (number of days spent from beginning to given date) of given year (Refer offsetDays() below)
2) Let offset found in above step be offset1. Find result year y2 and offset of result year offset2 (Refer highlighted code below)
3) Find days and months from offset2 and y2. (Refer revoffsetDays() below).
Below is the implementation of above steps.
d2 = 14, m2 = 3, y2 = 2016
This article is contributed by Anuj Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Total number of days taken to complete the task if after certain days one person leaves
- Program to convert given number of days in terms of Years, Weeks and Days
- Find day of the week for a given date
- Date class in Java (With Examples)
- Zeller's Congruence | Find the Day for a Date
- Convert String to Date in Java
- PHP | Converting string to Date and DateTime
- Program to check if a date is valid or not
- Java | Current date and time
- Time Functions in Python | Set-2 (Date Manipulations)
- Java | Date format validation using Regex
- Sort a multidimensional array by date element in PHP
- Python program to find day of the week for a given date
- C++ Program to print current Day, Date and Time