且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计算两个日期之间的天数,不包括周末

更新时间:2023-01-31 14:22:23

没有AFAIK这样的功能。但是,编写查询来计算该值很容易:

There is AFAIK no such function. It is however easy to write a query that calculates this:

with cal(d) as ( 
    values date('2015-01-01') -- start_date 
    union all 
    select d + 1 day from cal 
    where d < '2015-01-15'    -- end_date 
) select count(case when dayofweek(d) between 2 and 6 then 1 end) 
  from cal;

如果您进行了大量此类计算,则可能要创建日历表,则可以在此表中添加国定假日等属性。

If you do a lot of these kind of calculations you might want to create a calendar table, you can add attributes like national holiday etc to this table.