mysql的hql语句之时间段查询

来源:互联网 发布:淘宝v6会员帐号值钱吗 编辑:程序博客网 时间:2024/06/05 14:48

在网上查询好多时间段查询语句,但没解决我的问题,后来发现是我用错了类型。我以为时间段查询,那么数据库查询语句应该用date类型,但其实不然应使用String类型作为条件

如:

"from 表名 o where o.createDate between '"+starttime+"' and '"+endtime+"'";
或者用>=starttime and <=endtime也可以,这里如果你已经用Data类型接收了数据,那么转化为String类型就可以了
例如:

 String dateStr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(starttime); String dateend = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(endtime);
这样就可以转为String类型了,日期可以改为你需要的格式

如果我有什么地方写的不完善,或者错误,请各位评论指正,我会做出修改

原创粉丝点击