Oracle各种时间查询

1.获取时间的日:
select to_char(sysdate,’dd’) as nowday from dual
2. –获取时间的时:
select to_char(sysdate,’hh24’) as nowhour from dual;
3.–获取时间的分:
select to_char(sysdate,’mi’) as nowminute from dual;
4.–获取时间的秒:
select to_char(sysdate,’ss’) as nowsecond from dual;
5.–当前星期几
select to_char(sysdate,’day’) from dual;
6.–本周整周日期(以周日为第一天算)
select trunc(sysdate,’d’), trunc(sysdate,’d’)+7 from dual;
7.–下周开始日期
select trunc(sysdate,’d’)+7 from dual;
下周整周日期
select trunc(sysdate,’d’)+7,trunc(sysdate,’d’)+14 from dual;
8.–本月开始日期
select trunc(sysdate,’mm’) from dual;
9.–本月结束日期
select last_day(trunc(sysdate))from dual;
10.–下个月开始日期
select add_months(trunc(sysdate, ‘mm’), 1) from dual;
11.–本季开始日期
select trunc(sysdate,’Q’)from dual;
12–本年开始日期
select trunc(sysdate,’yyyy’) from dual;
13–本年结束日期
select add_months(trunc(sysdate,’yyyy’),12)-1 from dual;
14.
select to_char(sysdate, ‘iw’) as week, –今年已过周
to_char(sysdate, ‘ww’) as week2, –周
to_char(sysdate, ‘ddd’) as day, –今年已过天
to_char(sysdate, ‘q’) as quarter – 今年已过季度
from dual;
注:ww的算法为每年1月1日为第一周开始,date+6为每一周结尾
iw的算法为星期一至星期日算一周,且每年的第一个星期一为第一周

你可能感兴趣的:(oracle)