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