oracle日期计算问题

如何根据某天:testDay(格式2008-07-08)
计算出:
本周(testDay所在的周)的周一(this_week_beg)和周末(this_week_end),
上周的周一(last_week_beg)和周末(last_week_end ),
上上周的周一(two_week_beg)和周末( two_week_end),
上上上周的周一(three_week_beg)和周末(three_week_end),
本月开始(this_month_beg)和结束( this_month_end),
上月开始(last_month_beg)和结束(last_month_end).
谢谢了….

testday-6 ?

to_char(testday,'day') 是取该日是一周的第几天
周日是第一天,周一是第2天,周六是第7天
我们一般的习惯是以周日为最后天的,和数据库有所不同啊
我们这的本周日,在数据库里是下一周的开始(西方的习惯)

我不明白"decode(to_char(testday,'day'),'1',testday-6,testday-to_number(to_char(testday,'day'))+1)"
==>"decode(to_char(2008-07-08,'day'),'1',2008-07-08-6,2008-07-08-to_number(to_char(testday,'day'))+1)"?

 

应该是decode(to_char(testday,'day'),'1',testday-6,testday-to_number(to_char(testday,'day'))+2)"

这句话的意思
判断
to_char(testday,'day') 的值
如果是1,说明testday是周日,那取周一就是testday减去6天
不是的话,就取testday-to_char(testday,'day') 的值再加2天就是周一

比如8.25是周一
to_char(testday,'day')=2
8.25-2+2=8.25
如果是8.26
就是8.26-3+2=8.25
今天是
8.27
to_char(8.27,'day')=4
8.27-4+2=8.25

8.24是周日,如果还按这个公式算
8.24-1+2=8.25

按我们的习惯8.24不是本周的,算上周的,所以这时就要换个公式
8.24-6=8.18 就是上周一

非常感谢…..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值