Home>Article>Database> How to convert time type in mysql database

How to convert time type in mysql database

王林
王林 Original
2020-09-27 14:36:03 3962browse

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)) //时间

Commonly used date and time functions:

1. Get the current date:

CURRENT_DATE()

or

CURDATE()

2. Get the current time:

CURRENT_TIME()

or

CURTIME()

3. Get the current date and time

CURRENT_TIMESTAMP()

or

NOW()

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!

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