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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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 the day of the week after K days from the given day
- Program to calculate the number of odd days in given number of years
- Find minimum possible digit sum after adding a number d
- Check whether the number can be made perfect square after adding 1
- Check whether the number can be made perfect square after adding K
- Check whether the number can be made palindromic after adding K
- Find number of days between two given dates
- Python program to find number of days between two given dates
- Maximize the median of the given array after adding K elements to the same array
- Finding number of days between two dates using StringStream
- PHP | Number of week days between two dates
- C program to print number of days in a month
- Maximize number of days for which P chocolates can be distributed consecutively to N people
- Check whether N can be a Perfect Cube after adding or subtracting K
- Count distinct elements after adding each element of First Array with Second Array
- Find temperature of missing days using given sum and average
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Converting seconds into days, hours, minutes and seconds