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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the day number in the current year for the given date
- 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
- Program to check if a date is valid or not
- Convert String to Date in Java
- PHP | Converting string to Date and DateTime
- Date class in Java (With Examples)
- Zeller's Congruence | Find the Day for a Date
- Java | Current date and time
- Sort a multidimensional array by date element in PHP
- C++ Program to print current Day, Date and Time
- Python program to find day of the week for a given date
- Java | Date format validation using Regex
- Time Functions in Python | Set-2 (Date Manipulations)
- Convert timestamp to readable date/time in PHP
- Program to Convert Milliseconds to a Date Format in Java
- How to calculate the Easter date for a given year using Gauss' Algorithm
- Program to calculate the number of odd days in given number of years