SQL Server and Oracle acquisition time and date difference
1. Get System Current Time
SQL Server 2005:
Select GETDATE ()
The GETDATE () function returns the current time and date from SQL Server.
Grammar
GETDATE () instance
Example 1
Use the following SELECT statement:
Select GETDATE () as currentdatetime result:
Currentdatetime
2008-12-29 16:25:46.635
Oracle
Select Sysdate from dual
Select To_char (sysdate, ' DD ') from dual; --20
Select To_char (sysdate, ' d ') from dual; --5
Select To_char (sysdate, ' DDD ') from dual; --263
Select To_char (sysdate, ' WW ') from dual; --38
Select To_char (sysdate, ' W ') from dual; --3
Select To_char (sysdate, ' Yyyy/mm/dd hh24:mi:ss ') from dual; --2007/09/20 15:24:13
Select To_char (sysdate, ' Yyyy/mm/dd hh:mi:ss ') from dual; --2007/09/20 03:25:23
Select To_char (sysdate, ' J ') from dual; --2454364
Select To_char (sysdate, ' Rr/mm/dd ') from dual; --07/09/20
2. Get Year date
SQL Server 2005:
The code is as follows:
Select Year (getdate ())--2011
Select Month (getdate ())--3
Select Day (getdate ())--23
Oracle
The code is as follows:
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
Select To_char (sysdate, ' yyyy ') from dual; --2007
Select To_char (sysdate, ' yyy ') from dual; --007
Panax Notoginseng Select To_char (sysdate, ' yy ') from dual; --07
Select To_char (sysdate, ' mm ') from dual; --09
Q Quarter
hh hours (a)
Hh24 hours (in)
Mi minutes
SS sec
D Week of week