Home > Database > Oracle > body text

How to convert time date into timestamp in oracle

青灯夜游
Release: 2022-03-25 17:20:09
Original
23887 people have browsed it

Conversion method: 1. Use the to_char() function to output the time and date in the specified format. The result is a string, the syntax is "to_char(date,"conversion format")"; 2. Use to_date () function, syntax "to_date("time string","converted time and date format")".

How to convert time date into timestamp in oracle

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

oracle time and date conversion into timestamp

In Oracle, there are two methods to convert time and date into timestamp:

  • to_char() function

  • to_date() function

##1. to_char()

Output the time and date in the specified format, and the result is a string, not a date type.

to_char(日期,"转换格式" )
Copy after login

will convert the given date according to the "conversion format".

Example:

select to_char(sysdate, 'yyyy-mm-dd') from dual;
select to_char(sysdate, 'yyyy/mm/dd') from dual;
select to_char(sysdate, 'yyyymmdd') from dual;
select to_char(sysdate, 'yyyymmdd hh24:mi:ss') from dual;
Copy after login

You can also use to_char() to get a separate string of year, month, day, hour, minute and second

select to_char(sysdate,'yyyy') from dual;
select to_char(sysdate,'mm') from dual;
select to_char(sysdate,'hh24') from dual;
select to_char(sysdate,'mi') from dual;
Copy after login

2, to_date()

Convert the string to the specified time and date format

to_date("时间字符串","转换的时间日期格式")
Copy after login

The format of the two parameters must match, otherwise an error will be reported.

That is, the first parameter is interpreted according to the format of the second parameter.

Example:

select to_date('20220103','yyyymmdd') from dual;
select to_date('20220103','yyyy-mm-dd') from dual;
select to_date('20220103','yyyy/mm/dd') from dual;
select to_date('20220103','yyyy-mm-dd hh24:mi:ss') from dual;
Copy after login

Recommended tutorial: "

Oracle Tutorial"

The above is the detailed content of How to convert time date into timestamp in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template