数据库中存的是类似 2001-01-1格式的数据,现在在页面接收字符串 200101  想把2001年01月份的数据都查出来 ,怎么操作   谁能给个思路

解决方案 »

  1.   

    求1月和2月之间的数据,用sql的where条件。下面是oracle数据库的,不同数据库不一样
    select * from YourTable
    where a_date>=to_date('2010-01-01', 'yyyy-MM-dd') 
      and a_date<to_date('2010-02-01', 'yyyy-MM-dd') 
      

  2.   

    不是用SQL来做啊  我是从页面上来查询的
      

  3.   

    select * from 表名 where 日期 like '2001-01-1'
      

  4.   

    吧200110转换成java.util.Date类型
    Date dd = new SimpleDateFormat("yyyy-MM-dd").format("200101");
    然后写查询语句
      

  5.   

    哦,,你可以用SimpleDateFormat来设置日期格式啊。。用format将日期转换为字符串形式,这样就可以得到你想要的2001-01-1格式的啊。你试试哦一般涉及到日期的都用这个SimpleDateFormat。。
      

  6.   

    //获取日期
    String month = map.get("month").toString();
    //时间转化
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
    java.sql.Date startDate = null;
    try {
    if (!"".equals(month)) {
    startDate = new java.sql.Date(sdf.parse(month).getTime());
    }
    } catch (ParseException e) {
    e.printStackTrace();
    log.error("日期格式转化错误");
    throw new HdbException(e.getMessage(), "hedbsqlerror");
    }
      

  7.   


    //不知,lz想要什么样的
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    String strStart ="201001";
    String strEnd=strStart;

    strStart = strStart+"01"; //月头时间20100101
    Date date = sf.parse(strStart);

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    strEnd = strEnd+cal.getActualMaximum(Calendar.DAY_OF_MONTH); //月尾时间20100130
      

  8.   

    String querySql ="select * form table where " + "条件";
    if (!"".equals(month)) {
    querySql += " and time = '"+startDate+"'";
    }