The problem is to find the week number of year of a given date (in dd/mm/yy format).
Input: date = "02/01/2019" Output: 1 Explanation: We can check from the calendar that 2nd January 2019 lies in 1st week of 2019. Input: date = "08/09/2019" Output: 36
We will assign each day of the week a number. Let’s say Sunday is assigned 1 and Monday is assigned 2 and so on we assign numbers to other days. According to our convention, each week starts with Sunday and ends on Saturday.
So, suppose today is Monday and hence, the week number is also 1. After 20 days, the week number will be obviously 3rd.
20 days = 7+7+6 days
On carefully observing, we can see that week number after p days can be calculated using the formula mentioned below.
Week Number = least integer [ p/7 ]
(Least integer value of x is the smallest integer greater than or equal to x. For example, the Least integer value of 8.9 is 9 and that of 8 is 8).
We can use the above concept to find the week number of a given date as follows:
- Find the day number of 1st January of given year. Let’s call it x.
- Now, find the number of days before given date in given year. Let’s call it y.
- We can calculate the week number using the formula below
Week Number = least integer [ (x+y)/7 ]
Example: Below is the implementation of above approach.
- Before clicking the button:
- After clicking the button:
- How to get current year in PHP ?
- How to get current function name in PHP?
- How to get the size of screen, current web page and browser window using jQuery?
- Get the current URL using jQuery?
- How to get the current date and time in seconds?
- How to Get the Current Working Directory in Golang?
- How to get the path of current script using Node.js ?
- How to get title of current HTML page using jQuery ?
- How to Get Current time in Golang?
- How to Get Current Weekday in Golang?
- How to Get Current Date and Time in Various Format in Golang?
- Get current timestamp using Python
- How to get the current URL using AngularJS ?
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.