Given a string str which represents a date formatted as YYYY-MM-DD, the task is to find the day number for the current year. For example, 1st January is the 1st day of the year, 2nd January is the 2nd day of the year, 1st February is the 32nd day of the year and so on.
Input: str = “2019-01-09”
Input: str = “2003-03-01”
- Extract the year, month and the day from the given date and store them in variables year, month and day.
- Create an array days where days[i] will store the number of days in the ith month.
- Update count = days + days + … + days[month – 1] to get the count of all the past days of previous months.
- If the given year is a leap year then increment this count by 1 in order to count 29th February.
- Finally, add day to the count which is number of the day in the current month and print the final count.
Below is the implementation of the above approach:
- Write a program to reverse digits of a number
- Program to find whether a no is power of two
- Write an Efficient Method to Check if a Number is Multiple of 3
- Program to find parity
- Write an Efficient C Program to Reverse Bits of a Number
- Minimum number of jumps to reach end
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Print all combinations of points that can compose a given number
- Find Union and Intersection of two unsorted arrays
- Check if a number is multiple of 5 without using / and % operators
- To find sum of two numbers without using any operator
- Find day of the week for a given date
- Given a number, find the next smallest palindrome
- Find the element that appears once
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.