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 firstname.lastname@example.org. 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.
- Find the day number in the current year for the given date
- Program to convert given number of days in terms of Years, Weeks and Days
- Total number of days taken to complete the task if after certain days one person leaves
- Find day of the week for a given date
- Convert String to Date in Java
- PHP | Converting string to Date and DateTime
- Date class in Java (With Examples)
- Program to check if a date is valid or not
- Zeller's Congruence | Find the Day for a Date
- Java | Current date and time
- Time Functions in Python | Set-2 (Date Manipulations)
- Sort a multidimensional array by date element in PHP
- Python program to find day of the week for a given date
- Java | Date format validation using Regex