一、Orcale 时的查询
String hql = "from SmsTemplate t where 1=1 ";
if (model != null && !"".equals(model.getEndTimes())&& null!=model.getEndTimes() ) {
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //格式化当前系统日期
Date endt = model.getEndTimes();
String dateTime = dateFm.format(endt);
hql += " and t.endTimes<= to_date('" + dateTime+"' ,'yyyy-mm-dd')"; //注意单引号
//hql += " and t.endTimes<= to_date('" + dateTime+"' ,'yyyy-mm-dd HH24:mi:ss')";//带时、分、秒 注意 mi
//注:endTimes在数据库中时DATE型的
}
二、普通SQL Server 查询
DECLARE @dt DATETIME
DECLARE @dt2 DATETIME
SET @dt = '2008-07-24'
SET @dt2 = DATEADD(day, 1, @dt)
select @dt as dt, @dt2 as dt2
select * from meet_now where meetdate between CONVERT(datetime , @dt, 111 ) and convert(datetime , @dt2, 111 ) order by id
select * from meet_now where DATEDIFF(day, meetdate, @dt) = 0 order by id