Oracle datetime and String convert

Source: Internet
Author: User
Tags time interval

To_date ("String to convert", "converted format") The format of the two parameters must match, otherwise it will be an error.

That is, the first argument is interpreted in the format of the second parameter.

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

Format of conversion:

Represents year's: Y represents the last 2 digits of the year yyy represents the last 3 digits of the year yyyy in 4-digit years

MM with 2 digits for month; Mon in abbreviated form such as November or Nov; month with full name such as November or November

Indicates day: DD indicates days of the month, DDD indicates the day of the year, DY when in for a few days, such as Friday or Fri;day when in a few days to write all

Like Friday or Friday.

Represents hour: HH 2 digits for hour 12, hh24 2 digits for hours 24 hours

Represents minute: Mi 2 digits for minutes

Represents second: SS 2 digits for seconds 60 binary

Indicates quarterly: Q A number represents quarter (1-4)

There is also WW used to indicate the week of the year when W is used to denote the month ordinal.

Time range under 24-hour system: 00:00:00-23:59:59

Time range under 12-hour system: 1:00:00-12:59:59

Like what:

Select To_char (sysdate, ' Yy-mm-dd hh24:mi:ss ') from dual//display: 08-11-07 13:22:42

Select To_date (' 2005-12-25,13:25:59 ', ' Yyyy-mm-dd,hh24:mi:ss ') from dual//display: 2005-12-25 13:25:59

And if the writing: Select To_date (' 2005-12-25,13:25:59 ', ' yyyy-mm-dd,hh:mi:ss ') from the dual, will be an error, because the hour HH is 12 binary, 13 is illegal input, can not match.

Add:

Time minus 7 minutes for the current time
Select Sysdate,sysdate-interval ' 7 ' MINUTE from dual
The current time minus 7 hours of time
Select Sysdate-interval ' 7 ' hour from dual
The current time minus 7 days
Select Sysdate-interval ' 7 ' Day from dual
Time minus July for current time
Select Sysdate,sysdate-interval ' 7 ' month from dual
Time minus 7 years in the current time
Select Sysdate,sysdate-interval ' 7 ' year from dual
Time interval multiplied by a number
Select Sysdate,sysdate-8*interval ' 7 ' hour from dual

Dual Pseudo-column

Meaning explanation:

Dual is an actual table in Oracle that can be read by any user, often in a SELECT statement block without a target table .

For example, I want to get the system time, then use "Select Sysdate from Dual" to return to the system current time: 2008-11-07-9:32:49, different systems may return dates that are not in the same format. "Select User from dual" returns the user who is currently connected. If "Select 1+2 from Dual", results returned: 3

Oracle datetime and String convert

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.