Paip. Methods for taking the day's records SQL and HQL hibernate
#------of two ways ... function method and Date calculation method:
Function method: DATEDIFF (D,createtime,getdate ()) =0//d specified as Day
HB also has the same function:
Date calculation method: Where createtime>= ' 2014-5-4 00:00:01 ' and createtime<= ' 2014-5-4 23:59:59 '
where createtime= ' 2014-5-4 00:00:00 '
The date calculation should be used preferentially, because this method can use the index ... Do not convert a datetime to a long number ...
Author of Old Wow's Paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
#-----as follows
Public awardweixin Todayjoinrecode (string uid, string actid) {
12:53:37 2014-4-30
Session session = GetSession ();
String hql = "from awardweixin where ActivityID =?" and openid=? and createtime=? ";
List<awardweixin> awardlist = null;
Query q = session.createquery (HQL);
Q.setparameter (0, Actid);
Q.setparameter (1, UID);
Q.setparameter (2, Dateutil.today_notime ());
Awardlist = Q.list ();
if (awardlist.size () = = 0)//new user Add 3tsi
// {}
System.out.println (Awardlist.size ());
Return Awardlist.get (0);
}