Oracle Date Usage

Source: Internet
Author: User

1. Get system time, current time

Select sysdate from dual

2. Date function

When using date calculations in SQL statements, you must use a Date function to convert the string to a date type, unlike using a string directly in SQL Server.

to_date ("string", "converted format")

To_char (date, "convert format") converts the given date according to "conversion format"

Such as:

Query column dcolum (date column) less than 2012-12-1 of data
Select dcolum<to_date (' 2012-12-1 ', ' yy-mm-dd ') from table

3. Date Plus and minus operation

Sysdate+/-1 Plus/minus one day

SYSDATE+/-1/24 Plus/minus 1 hours

SYSDATE+/-1/(24*60) plus/minus 1 minutes

sysdate+/minus 1/(24*60*60) plus/minus 1 seconds

Analogy to milliseconds 0.001 seconds

Add_months (Sysdate,+/-number) plus/minus designated month

Select sysdate+1 from dual

Select add_months (sysdate,12) from dual plus one year

4. Format mask for conversion

  Classic usage: ' Yyyy-mm-dd hh24:mi:ss ' means: ' 2015-09-23 16:05:00 '

bold is common format, others for reference

yyTwo digits two-year
YYY three digits three-year
yyyyFour digits four-year

Month:
mmNumber two-month
Mon abbreviated Character Set representation
Month spelled out character set representation

Day:
DDNumber of days in the month
DDD Number The first day of the year
DY abbreviated when in for a few days
Day spelled out when in days are all written

Hour:
HH digits 12-hour binary
hh2424-hour binary digits

Minute:
miDigits 60 binary

Second:
SSDigits 60 binary

Other
Q Digit Quarter
WW Digit The first few weeks of the year
W Digit Week of the month

More......

Oracle Date Usage

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.