数据表里有一个month字段,类型是datetime,里面存贮的时间格式为 0000-00-00 我现在要查询要某个月份里面的所有数据
我怎么做啊?
我下面写的不对啊 前台传过来的数据 转换成Date类型后是GMT格式的  比不了啊?我该怎么做?
public PagerModel getSal(int firstResult, int maxResults, Date startdate,Date enddate) {

String hql  = "select count(*) from Salary where month between" + " " + startdate + " " + "and" + " " + enddate;
int total = ((Long)sessionFactory.getCurrentSession().createQuery(hql).uniqueResult()).intValue();
List datas = sessionFactory.getCurrentSession().createQuery("select s from Salary as s where month between" + " " + startdate + " " + "and" + " " + enddate)
.setFirstResult(firstResult)
.setMaxResults(maxResults).list();
PagerModel pm = new PagerModel();
pm.setTotal(total);
pm.setDatas(datas);
return pm;
}

解决方案 »

  1.   

    String hql = "select s from Salary s where month between ? and ?";session.createQuery(hql).setParameter(0, startdate).setParameter(1, enddate).list();
      

  2.   

    现在month里的数据和传进来的根本没法比啊  month里的格式是0000-00-00的  而传进来的Date类型是
    Mon Mar 01 00:00:00 CST 2010  这种样子的  怎么办
      

  3.   


    select count(*) from Salary where month between to_date("+startdate +",'YYYY-MM-DD') and to_date("+startdate +",'YYYY-MM-DD')
      

  4.   


    MySQL有to_date这个用法吗?
      

  5.   


    或者先
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    string  startdateStr =sdf.format(startdate);
    以后想这么操作都由你啊
      

  6.   

    oracle有 MySQL的日期函数不清楚,你查下。
      

  7.   

    这样不是变成String类型的了吗  我怎么还能和Date类型的进行比呢
      

  8.   

    用大于小于号就可行了吧 我这里没有mysql  要不给你运行下 呵呵
      

  9.   

    1.用SimpleDateFormat将前台数据转成字符串;
    2.用to_char将数据库中的数据转成字符串,比较。
      

  10.   

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    string startdateStr =sdf.format(startdate);这个东西不能小看
      Date-->String  你想要的格式
      String-->Date  你想要的格式
    你要什么类型的随便转化
      

  11.   

    为什么我这么用后:
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date d1 = sdf.parse("2010-3-1");
    出来的日期格式还是这种:
    Mon Mar 01 00:00:00 CST 2010
      

  12.   


    你用 convert(varchar(10),startdate,120 )  把数据库的data类型转为String  
    用String比较吧
      

  13.   

    http://blog.csdn.net/chosen0ne/archive/2010/01/06/5139930.aspx
    楼主看下,可不可以帮到你