从周号获取一周的第一天 [英] Get First Day Of Week From Week Number

查看:100
本文介绍了从周号获取一周的第一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle中,有没有简单的方法可以根据周数获得一周的第一天?

In Oracle, is there a straightforward way to get the first day of the week given a week number?

例如,今天的日期是2012年12月4日.如果我运行: 从双中选择to_char(sysdate,'WW'); 返回第49周.

For example, today's date is 12/4/2012. If I run: select to_char(sysdate,'WW') from dual; It returns 49 for the week number.

我想做的是第一天返回2012年12月2日...给定第49周(假设星期日为一周的第一天).

What I would like to do is somehow return 12/2/2012 for the first day...given week 49 (assuming Sunday as first day of the week).

有什么想法吗?预先感谢您的帮助!

Any ideas? Thanks in advance for any help!

推荐答案

尝试一下:

select next_day(max(d), 'sun') requested_sun
  from (select to_date('01-01-2012', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
 where to_char(d, 'ww') = 49-1;

只需设置您的年份to_date('01-01-2012'和第1周49-1(如果适用).

just set your year to_date('01-01-2012' and week number-1 49-1 as applicable.

2008年第49周的星期天?

the sunday in the 49th week of 2008?

SQL> select next_day(max(d), 'sun') requested_sun
  2    from (select to_date('01-01-2008', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
  3   where to_char(d, 'ww') = 49-1;

REQUESTED
---------
07-DEC-08

和2012

SQL> select next_day(max(d), 'sun') requested_sun
  2    from (select to_date('01-01-2012', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
  3   where to_char(d, 'ww') = 49-1;

REQUESTED
---------
02-DEC-12

这篇关于从周号获取一周的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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