SQL Server and Oracle acquisition time and date difference

Source: Internet
Author: User
Tags current time getdate time and date

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.