Home > Database > Mysql Tutorial > body text

Detailed explanation of the method of converting varchar type to date type in MySQL

怪我咯
Release: 2017-03-30 11:08:25
Original
7962 people have browsed it

The following table:

Detailed explanation of the method of converting varchar type to date type in MySQL

First use str_to_datefunction to convert its varchar type For the date type, then sort from small to large

Syntax: select str_to_date(class_time,'%Y%m%d %H:%i:% s') a from a order by a desc ;

Detailed explanation of the method of converting varchar type to date type in MySQL

Let’s take a look at the date format conversion of varchar type in Oracle to date type

Varchar type date format conversion date type in oracle

SELECT to_char(to_date(m.ma_datetime,'yyyy-MM-dd hh24:mi:ss'),
 'yyyyMMdd') FROM my_task m;
Copy after login

m.ma_datetime is a varchar2 type date format, first convert the date type

( Hours, minutes and seconds must be added, otherwise ora-01830 error will be reported)

Then convert it to varchar type as you like

The above is the detailed content of Detailed explanation of the method of converting varchar type to date type in MySQL. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!