如何从mysql查询中提取日期和时间部分

时间:2015-05-13 15:59:15

标签: mysql select max datepart

我需要从MySQL表中选择一个max(日期),并将日期和时间的每个部分放在一个单独的变量中。

类似的东西:

select max(date) as year, month, day, hour, minute, second from table

我该怎么做?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

SELECT 
YEAR ( MAX(date) ) as year,
MONTH ( MAX(date) ) as month, 
DAY ( MAX(date) ) as day,
HOUR( MAX(date) ) as hour,
MINUTE( MAX(date) ) as minute,
SECOND( MAX(date) ) as second
from table