计算SQL中2个日期之间的差异,不包括周末日 [英] Calculate diffference between 2 dates in SQL, excluding weekend days

查看:177
本文介绍了计算SQL中2个日期之间的差异,不包括周末日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个SQL查询,计算两个日期之间的差异,而不计算结果中的周末日期。

I would like to build an SQL query which calculates the difference between 2 dates, without counting the week-end days in the result.

有没有办法格式化日期以获取此结果?例如对于Oracle数据库:

Is there any way to format the dates to obtain this result ? For example for Oracle database :

select sysdate - creation_dttm from the_table


推荐答案

我已经找到了另一种方法来计算差异,只能使用SQL:

I have found another way to do calculate the difference, by using only SQL :

select sysdate - creation_dttm
- 2 * (to_char(sysdate, 'WW') - to_char(creation_dttm, 'WW'))
from the_table

这篇关于计算SQL中2个日期之间的差异,不包括周末日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆