mysql日期/时间转换为字符串

将日期时间2016-05-13 16:07:50转化为字符串20160513

date_format

SELECT 
    phone, DATE_FORMAT(time, '%Y%m%d%H%i%s')
FROM
    user
WHERE
    phone = 'xxxxxxxx'; 
    #20160513160750

SELECT 
    phone, DATE_FORMAT(time, '%Y%m%d')
FROM
    user
WHERE
    phone = 'xxxxxxxx'               
#20160513
SELECT 
	reportStatus, date_format(reportDateTime, '%Y-%m-%d %H:%i:%s') reportDateTime
FROM
	doorSensorDevice
WHERE
	deviceId = #{deviceId}
		AND reportStatus IS NOT NULL
ORDER BY reportDateTime DESC
LIMIT #{startNum} , #{pageSize}

 

你可能感兴趣的:(Mysql,工具)