数据库是access,现在需要取得系统时间,然后和输入的年龄相比较,最后得出一个界限年限把符合符合条件的记录全部取出
例如:取得系统当前时间20050606,输入年龄〉35,就需要经过比较得出19700606,然后把数据库中日期在19700606以前的记录全部取出
需要解决的具体问题
(1)取得系统时间20050606
(2)由20050606和45得出19700606,包括格式转换
(3)把数据库中出生时间<或>19700606的记录全部取出的SQL语句
第一个问题简单,我也能查出来,主要是时间取出来之后的格式转换和处理不知道该怎么办,还有什么样的SQL语句才能对数据库中时间日期格式的记录进行比较也不知道
希望大家能帮我一下,给出各部分的相应代码
问题解决,马上结贴

解决方案 »

  1.   

    取出的时间用STRING的format格式化成SQL语句需要的格式。
      

  2.   

    int iInput = 35;
        Calendar d = Calendar.getInstance();
        d.add(Calendar.YEAR,-iInput);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String s = sdf.format(d.getTime());
        String strSql = "select * from table1 where birthday < #" + s + "#";
        System.out.println("strSql:" + strSql);
      

  3.   

    to duanzilin(寻) 
    试试你的方法,看看能不能解决
      

  4.   

    1.  Calendar now = Calendar.getInstance();
    SimpleDateFormat yearAndMonth = new SimpleDateFormat("yyyy-MM-dd");
    String retString = yearAndMonth.format(now.getTime());
    2.
                      now.add(Calendar.YEAR,-iInput);
    yearAndMonth = new SimpleDateFormat("yyyy-MM-dd");
    retString = yearAndMonth.format(now.getTime());
    3.
                  String strSql = "select * from table1 where convert(VARCHAR(10),birthday ,120)>"+retString ;
      

  5.   

    Calendar要 import 什么呀?
      

  6.   

    import java.util.*;
    import java.text.*;