您好,欢迎访问一九零五行业门户网

mysql日期时间比较简单实例

日期比较,mysql
 代码如下 复制代码
select * from tb where c> date_format('2007-07-06','%y%m%d') and c
select * from tb where c> date('2007-07-07') and c
statday是形如2006031001的日期数据字段
 代码如下 复制代码
select * from loginstat where statday> date_format(curdate()-1,'%y%m%d') and statday >= date_format(curdate(),'%y%m%d');或者:select * from loginstat where statday> date_format(curdate()-1,'%y%m%d%h') and statday >= date_format(curdate(),'%y%m%d%h');
其他用法:
 代码如下 复制代码
select * from loginstat where statday >= date_format('$date1','%y%m%d%h') and statday
mysql数据库中存的时间格式为2008-12-28 18:08:08,现在先要从一个一个结果集rs中获得一个日期时间。我先用rs.getdate()方法试着获取时间,结果只有年月日,无法获取小时、分和秒。最后解决的方法是:
 代码如下 复制代码
date time1=new date(rs.gettimestamp(pub_time).gettime());
simpledateformat formattime = new simpledateformat(yyyy-mm-dd hh:mm:ss);
string pubtime=formatime.format(time1);
获得的pubtime为string型,在sql语句中用mysql的时间函数date_format('time','format')转换:
 代码如下 复制代码
string sqlstr=select * from do_document where pub_time
然后执行该sql语句就查到了满足条件的记录
其它类似信息

推荐信息