How to get total number of Sunday’s for given date in postgresql
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.
The total number of Sundays for a given date can only be either 0 or 1.
But if you want the number of Sundays within a given date range, then your best bet is a calendar table. To find how many Sundays are in February this year, I’d just
or
Here’s a basic calendar table that you can start with. I also included a PostgreSQL function to populate the calendar table. I haven’t tested this in 8.3, but I’m pretty sure I’m not using any features that 8.3 doesn’t support.
Note that the “dow” parts assume your days are in English. But you can easily edit those parts to match any language. (I think. But I could be wrong about “easily”.)
And a rudimentary function to populate the table. I haven’t tested this in 8.3 either.