//数据库为mysql 用HQL语句查询比较时间
import java.util.Calendar;
Date date = new Date();
Calendar ca = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//计算查询的时间间隔
ca.add(Calendar.DATE, -30);一个月内的订单
date = ca.getTime();
import java.util.Calendar;
Date date = new Date();
Calendar ca = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//计算查询的时间间隔
ca.add(Calendar.DATE, -30);一个月内的订单
date = ca.getTime();
hql for mysql: "and m.createTime >='"+ sdf.format(date) +"' and m.createTime <= current_date() ";
注意:'"+ sdf.format(date) +"' 记住加上''单引号引上
本文介绍如何使用HQL查询MySQL数据库中特定时间范围内的记录,通过Java代码实现获取过去30天内的订单数据。
1046

被折叠的 条评论
为什么被折叠?



