Getting number of certain days-of-the-week (weekend) from interval in PostgreSQL

前端 未结 8 2217
轮回少年
轮回少年 2021-01-06 13:27

Given 2 timestamps in postgres, how do you calculate the time difference without counting whole Saturdays and Sundays?

OR

How do you count the number of Satu

8条回答
  •  佛祖请我去吃肉
    2021-01-06 14:12

    The best solution to this will be to use a calendar table. This is incredibly useful and you can do all sort of interesting things - including counting the number of working days between two dates or counting the number of holidays between two dates.

    This table is usually populated in advance - say for 20 years with the date for well known holidays appropriately tagged. If holidays shift, you maintain the table once in a while to mark the days as holidays. More info here and here. This uses MS SQL Server, but is easily ported as well.

提交回复
热议问题