SQL中查询日期语句

通过语句查询数据库中日期所在的周(一年内第多少周)和季度.望高手解答

select getdate() as 日期 ,
year(getdate()) as 年,
case month(getdate())
when 1 then '一月'
when 2 then '二月'
when 3 then '三月'
when 4 then '四月'
when 5 then '五月'
when 6 then '六月'
when 7 then '七月'
when 8 then '八月'
when 9 then '九月'
when 10 then '十月'
when 11 then '十一月'
when 12 then '十二月'
end as 月,

case datepart(weekday,getdate())-1
when 1 then '星期一'
when 2 then '星期二'
when 3 then '星期三'
when 4 then '星期四'
when 5 then '星期五'
when 6 then '星期六'
when 0 then '星期日'
end as 星期
,datepart(week,getdate()) as 年内的第几周
,datepart(quarter,getdate()) as 年内的第几季
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-04-13
SQL SERVER:

用函数datepart处理就可以了,示例:
select datepart(weekday,getdate()) as 周内的第几日

select datepart(week,getdate()) as 年内的第几周

select datepart(quarter,getdate()) as 年内的第几季

周内的第几日
-----------
5

(所影响的行数为 1 行)

年内的第几周
-----------
34

(所影响的行数为 1 行)

年内的第几季
-----------
3

(所影响的行数为 1 行)本回答被提问者采纳
第2个回答  2010-08-19
第几周:Select DatePart(week,'2010-08-19')
第几季度:Select DatePart(quarter,'2010-08-19')
第3个回答  2010-08-19
第几周:Select to_char(sysdate,'WW') from dual;
第几季度:Select to_char(sysdate,'Q') from dual;
相似回答