Oracle gets the current date and date format

Source: Internet
Author: User
Tags time interval

Oracle gets the current date and date format


Get system Date: Sysdate ()

Formatted Date: To_char (Sysdate (), ' Yy/mm/dd HH24:MI:SS)

or To_date (Sysdate (), ' Yy/mm/dd HH24:MI:SS)

Formatted number: To_number


Note: To_char converts a date or number to a string

To_char (number, ' format ')

To_char (Salary, ' $99,999.99 ')

To_char (date, ' format ')

To_date converting a string to a date type in a database

To_date (char, ' format ')

To_number converting a string to a number

To_number (char, ' format ')


return system date, output 2 May-December-09

Select Sysdate from dual;

Mi is minutes, output 2009-12-25 14:23:31

Select To_char (sysdate, ' Yyyy-mm-dd HH24:mi:ss ') from dual;

MM will display the month, output 2009-12-25 14:12:31

Select To_char (sysdate, ' Yyyy-mm-dd HH24:mm:ss ') from dual;

Output 09-12-25 14:23:31

Select To_char (sysdate, ' Yy-mm-dd hh24:mi:ss ') from dual

Output 2009-12-25 14:23:31


Select To_date (' 2009-12-25 14:23:31 ', ' Yyyy-mm-dd,hh24:mi:ss ') from dual

And if you write on the writing:

Select To_date (' 2009-12-25 14:23:31 ', ' Yyyy-mm-dd,hh:mi:ss ') from dual

will be error, because the hour HH is 12 binary, 14 is illegal input, can not match.


Output $10,000,00:

Select To_char (1000000, ' $99,999,99 ') from dual;

Output rmb10,000,00:

Select To_char (1000000, ' l99,999,99 ') from dual;

Output 1000000.12:

Select Trunc (To_number (' 1000000.123 '), 2) from dual;

Select To_number (' 1000000.123 ') from dual;


Format of conversion:

Representing year: Y represents the last of the years,

YY represents the last 2 digits of the year,

YYY represents the last 3 digits of the year,

YYYY 4-digit year


Indicates: mm with 2 digits for month,

Mon in shorthand form, such as November or Nov,

Month with full name, like November or November.


Represents day: DD indicates days of the month,

DDD indicates the day ordinal of the year

Dy when in a few days, shorthand, such as Friday or Fri,

Day when in days, full name, such as Friday or Friday


Represents hour: HH 2 digits represent hours 12 decimal,

Hh24 2-digit hour 24 hour


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


Number format: 9 represents a number

0 Force Display 0

$ place a $ character

L Place a floating local currency symbol

. Show decimal point

, displays the thousand indicator


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;


Comments:

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

Different systems may return dates that are not in the same format.

Returns the currently connected User: Select User from Dual;


Oracle gets the current date and date format

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.