sql server與oracle 擷取時間與日期區別
1.擷取系統目前時間
sql server 2005:
select getdate()
getdate() 函數從 sql server 返回當前的時間和日期。
文法
getdate()執行個體
例子 1
使用下面的 select 語句:
select getdate() as currentdatetime結果:
currentdatetime
2008-12-29 16:25:46.635
oracle:
select sysdate from dual
39 select to_char(sysdate,'dd') from dual; -- 20
40 select to_char(sysdate,'d') from dual; -- 5
41 select to_char(sysdate,'ddd') from dual; -- 263
42 select to_char(sysdate,'ww') from dual; -- 38
43 select to_char(sysdate,'w') from dual; -- 3
44 select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') from dual; -- 2007/09/20 15:24:13
45 select to_char(sysdate,'yyyy/mm/dd hh:mi:ss') from dual; -- 2007/09/20 03:25:23
46 select to_char(sysdate,'j') from dual; -- 2454364
47 select to_char(sysdate,'rr/mm/dd') from dual; -- 07/09/20
2.擷取年月日
sql server 2005:
代碼如下:
select year(getdate()) --2011
select month(getdate()) --3
select day(getdate()) --23
oracle:
代碼如下:
select to_char(sysdate,'yyyy') from dual --2011
select to_char(sysdate,'mm') from dual --03
select to_char(sysdate,'dd') from dual --23
select to_char(sysdate,'yyyy/mm/dd') from dual; -- 2007/09/20
35 select to_char(sysdate,'yyyy') from dual; -- 2007
36 select to_char(sysdate,'yyy') from dual; -- 007
37 select to_char(sysdate,'yy') from dual; -- 07
38 select to_char(sysdate,'mm') from dual; -- 09
q 季度
hh 小時(12)
hh24 小時(24)
mi 分
ss 秒
d 周中的星期幾