如何把系统时间和输入的年龄相比较的得出分界的日期然后把数据库中符合条件的记录取出

nodreamer 2005-06-06 10:47:43
数据库是access,现在需要取得系统时间,然后和输入的年龄相比较,最后得出一个界限年限把符合符合条件的记录全部取出
例如:取得系统当前时间20050606,输入年龄〉35,就需要经过比较得出19700606,然后把数据库中日期在19700606以前的记录全部取出
需要解决的具体问题
(1)取得系统时间20050606
(2)由20050606和45得出19700606,包括格式转换
(3)把数据库中出生时间<或>19700606的记录全部取出的SQL语句
第一个问题简单,我也能查出来,主要是时间取出来之后的格式转换和处理不知道该怎么办,还有什么样的SQL语句才能对数据库中时间日期格式的记录进行比较也不知道
希望大家能帮我一下,给出各部分的相应代码
问题解决,马上结贴
...全文
103 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
nodreamer 2005-06-11
  • 打赏
  • 举报
回复
结贴
谢谢各位兄弟
沝林 2005-06-06
  • 打赏
  • 举报
回复
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);
airhand 2005-06-06
  • 打赏
  • 举报
回复
取出的时间用STRING的format格式化成SQL语句需要的格式。
nodreamer 2005-06-06
  • 打赏
  • 举报
回复
怎么没人呢?
200分呀,都没人要
自己顶一下
沝林 2005-06-06
  • 打赏
  • 举报
回复
import java.util.*;
import java.text.*;
nodreamer 2005-06-06
  • 打赏
  • 举报
回复
Calendar要 import 什么呀?
laughsmile 2005-06-06
  • 打赏
  • 举报
回复
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 ;
nodreamer 2005-06-06
  • 打赏
  • 举报
回复
to duanzilin(寻)
试试你的方法,看看能不能解决

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧