Home > Database > Mysql Tutorial > body text

How to convert time type in mysql database

王林
Release: 2020-09-27 14:36:03
Original
3876 people have browsed it

Mysql database method for time type conversion: [UNIX_TIMESTAMP(DATE(NOW()))]. If you want to get the current date, you can use the CURRENT_DATE() method.

How to convert time type in mysql database

Conversion between Linux/Unix timestamp and MySQL time and date types:

(Recommended tutorial: mysql Video tutorial )

UNIX_TIMESTAMP(NOW())                   //将mysql的datetime转换成linux/unix的时间戳;日期时间
UNIX_TIMESTAMP(DATE(NOW()))       //将mysql的date转换成linux/unix的日期。
UNIX_TIMESTAMP(TIME(NOW()))        //将mysql的time转换成linux/unix的时间。(用问题)
FROM_UNIXTIME(time_t)                      //将unix的时间戳转换成mysql的datetime;日期时间
DATE(FROM_UNIXTIME(time_t))          //日期
TIME(FROM_UNIXTIME(time_t))           //时间
Copy after login

Commonly used date and time functions:

1. Get the current date:

CURRENT_DATE()
Copy after login

or

CURDATE()
Copy after login

2. Get the current time:

CURRENT_TIME()
Copy after login

or

CURTIME()
Copy after login

3. Get the current date and time

CURRENT_TIMESTAMP()
Copy after login

or

NOW()
Copy after login

Related recommendations: php training

The above is the detailed content of How to convert time type in mysql database. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!