ITPub博客

首页 > 数据库 > Oracle > [Oracle]常用日期取值方法

[Oracle]常用日期取值方法

原创 Oracle 作者:梓沐 时间:2016-02-15 10:11:17 0 删除 编辑
select
  sysdate,
  to_number(to_char(sysdate,'hh24')) 时,
  to_number(to_char(sysdate,'mi'))   分,
  to_number(to_char(sysdate,'ss'))   秒,
  to_number(to_char(sysdate,'dd'))   日,
  to_number(to_char(sysdate,'mm'))   月,
  to_number(to_char(sysdate,'yyyy')) 年,
  to_number(to_char(sysdate,'ddd'))  年内第几天,
  trunc(sysdate,'dd')                一天之始,
  trunc(sysdate,'day')               周初,
  trunc(sysdate,'mm')                月初,
  last_day(sysdate)                  月末,
  add_months(trunc(sysdate,'mm'),1)  下月初,
  trunc(sysdate,'yy')                年初,
  to_char(sysdate,'day')             周几,
  to_char(sysdate,'month')           月份
from
  dual;

------------------------------------------------

SYSDATE    2015-12-09 10:49:51
时         10
分         49
秒         51
日         9
月         12
年         2015
年内第几天  343
一天之始    2015-12-09
周初       2015-12-06
月初       2015-12-01
月末       2015-12-31 10:49:51
下月初     2016-01-01
年初       2015-01-01
周几       星期三
月份       12月

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29812844/viewspace-1988848/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
擅长PLS/QL开发,SQL调优和改写,数据库设计

注册时间:2014-08-18

  • 博文量
    161
  • 访问量
    1204432