当前位置: 代码迷 >> 综合 >> mysql 数据库 HQL语句查询一个月内时间的数据
  详细解决方案

mysql 数据库 HQL语句查询一个月内时间的数据

热度:83   发布时间:2024-01-18 03:32:19.0
//数据库为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();

hql for mysql: "and m.createTime >='"+ sdf.format(date) +"' and m.createTime <= current_date() ";

注意:'"+ sdf.format(date) +"'  记住加上''单引号引上


  相关解决方案