How do I find the number of fridays between two dates(including both the dates) using a select statement in oracle sql?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will do it:
Perhaps best if I break that down. The NEXT_DAY function returns the next day that is a (Friday in this case) after the date.
So to find the first Friday after d1 would be:
But if d1 is a Friday that would return the following Friday, so we adjust:
Similarly to find the last Friday up to and including d2 we do:
Subtracting the 2 gives a number of days: 0 if they are the same date, 7 if they a re a week apart and so on:
Convert to weeks:
Finally, if they are the same date we get 0, but really there is 1 Friday, and so on so we add one: