Home > Database > Mysql Tutorial > sql server与oracle 获取时间与日期区别

sql server与oracle 获取时间与日期区别

WBOY
Release: 2016-06-07 17:47:56
Original
1177 people have browsed it

sql server与oracle 获取时间与日期区别
1.获取系统当前时间
sql server 2005: 

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 周中的星期几

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template