赞
踩
DATE_FORMAT(date, format)
其中:
date 是要格式化的日期或时间。
format 是你希望得到的输出格式。
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d');
常见的格式化选项有:
%Y 年份,四位数
%y 年份,两位数
%m 月份,两位数
%d 日期,两位数
%H 小时,24小时制,两位数
%h 小时,12小时制,两位数
%i 分钟,两位数
%s 秒,两位数
%p AM/PM
@Data
public class AITimeDatePlay {
@DateTimeFormat(
pattern = "yyyy-MM-dd HH:mm:ss"
)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date testTime;
}
List<EmployeeInfo> queryInfomationByTime(AITimeDatePlay dto);
<select id="queryInfomationByTime" resultType="com.bonade.hrm.foundation.model.EmployeeInfo">
select *
from employee_info ei
where date_format(ei.initiation_time,'%Y-%m-%d') = DATE_FORMAT(#{testTime},'%Y-%m-%d')
</select>
select date_format(ei.initiation_time,'%Y-%m-%d') as bigTime
from employee_info ei
where date_format(ei.initiation_time,'%Y-%m-%d') = DATE_FORMAT(#{testTime},'%Y-%m-%d')
select date_format(ei.initiation_time,'%Y-%m') as bigTime
from employee_info ei
where date_format(ei.initiation_time,'%Y-%m') = DATE_FORMAT(#{testTime},'%Y-%m')
select date_format(ei.initiation_time,'%Y-%m') as bigTime
from employee_info ei
where (
((DATE_FORMAT( ei.initiation_time, '%Y-%m' )) BETWEEN #{startTime} AND #{endTime})
OR (( DATE_FORMAT( ei.leave_time, '%Y-%m' )) BETWEEN #{startTime} AND #{endTime})
)
select date_format(ei.initiation_time,'%Y-%m') as bigTime
from employee_info ei
where (
((DATE_FORMAT( ei.initiation_time, '%Y-%m' )) BETWEEN DATE_FORMAT(#{startTime},'%Y-%m') AND DATE_FORMAT(#{endTime},'%Y-%m'))
OR (( DATE_FORMAT( ei.leave_time, '%Y-%m' )) BETWEEN DATE_FORMAT(#{startTime},'%Y-%m') AND DATE_FORMAT(#{endTime},'%Y-%m'))
)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。