search
HomeCommon ProblemHow to convert oracle date format

How to convert oracle date format

Jul 23, 2019 pm 04:20 PM
oracle

How to convert oracle date format

Recommended tutorial: Oracle tutorial

This article mainly introduces date conversion in Oracle.

1. Convert date to string (take October 20, 2016 as an example)

##select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') strDateTime from dual; --Get year-month-day hour:minute:second --The displayed result is: 2016- 10-20 12:35:21

select to_char(sysdate,'yyyymmdd hh24:mi:ss') strDateTime from dual; --Get year, month, day, hour: minute :Seconds --The displayed result is: 20161020 13:39:25

select to_char(sysdate,'yyyymmdd') strDateTime from dual; -- Get the year, month and day --The displayed result is: 20161020

select to_char(sysdate,'yyyy') strYear from dual; --Get the year --The displayed result is: 2016

select to_char(sysdate,'mm') strMonth from dual; --Get the month --The display result is: 10

select to_char(sysdate,'dd') strDay from dual; --Get the day --The display result is :20

select to_char(sysdate,'hh24') strHour from dual; --When getting --The displayed result is: 13

select to_char(sysdate,'mi') strMinute from dual; --Get points --The displayed result is: 46

select to_char(sysdate,'ss') strSecond from dual; --Get seconds--The displayed result is: 43

2 . Convert string and time

select to_date('2010-10-20 13:23:44','yyyy-mm-dd hh24:mi:ss' ) dateTime from dual;

Display results: 2010/10/20 13:23:44

select to_date('2010-10-20 13:23:44 ','yyyy/mm/dd hh24:mi:ss') dateTime from dual;

Display result: 2010/10/20 13:23:44

select to_char( to_date(222,'J'),'Jsp') from dual;

Display results: Two Hundred Twenty-Two

If you write it according to the following example, it will Error: ORA-01849: hour value must be between 1 and 12. (Because hh is in hexadecimal and there is no 13, an error is reported)

select to_date('2005-12-25,13:25:59','yyyy-mm-dd,hh: mi:ss') from dual;

##3. Query the day of the week a certain day is##select to_char(to_date ('2012-10-20','yyyy-mm-dd'),'day') strDay from dual;

Display results: Saturday

select to_char (to_date('2012-10-20','yyyy-mm-dd'),'day','NLS_DATE_LANGUAGE = English') strDay from dual;

Display Result: saturday

4. The number of days between two dates

select floor(sysdate - to_date('20161010','yyyymmdd')) strTime from dual;

--where sysdate=2016/10/20 17:10:51--display result: 10

5. Usage of null time

select to_date(null) from dual;

6. Month difference

select months_between(date'2014-04-23',date'2013-04-23 ') days from dual;

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.