[Oracle]常用日期取值方法

梓沐發表於2016-02-15
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部落格 ” ,連結:http://blog.itpub.net/29812844/viewspace-1988848/,如需轉載,請註明出處,否則將追究法律責任。

相關文章