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;
select to_date('2010-10-20 13:23:44 ','yyyy/mm/dd hh24:mi:ss') dateTime from dual;
select to_char( to_date(222,'J'),'Jsp') from dual;
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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

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
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
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.