
时间的话,你直接将一个固定日期 例如2011-06-06加到时间前面去,就可以比较了吧。
你要比较的是同一日期的不同时间么?
php3.2中可以先把时间段拿出来。转换为字符串后。可以直接比较.如果只比较时间的话,可以转换为字符串后。截图年月日字段然后进行直接比较。
例子:
$loginwh = array()
$tomorrow = date("Y-m-d H:i:s", (strtotime($wh['add_time']) + 86399))//结束的时间
$day = $wh['add_time'] . ' 00:00:00'//开始的时间:获取的时间然后直接以年月日小时分秒的形式进行组合,接着成为一个条件进行比较
$loginwh['registerTime'] = array(array('egt', $day), array('elt', $tomorrow))数据库条件
一.存储日期的字段为日期类型MySql(Date、DateTime、TimeStamp等):
方法一:直接比较
select * from test where create_time between ‘2015-03-03 17:39:05’ and ‘2016-03-03 17:39:52’
方法二:用unix_timestamp函数,将字符型的时间,转成unix时间戳
select * from test where unix_timestamp(create_time) >
unix_timestamp(‘2011-03-03 17:39:05’) and unix_timestamp(create_time)
<unix_timestamp(‘2011-03-03 17:39:52’)
个人觉得这样比较更踏实点儿。
Oracle(Date,TimeStamp等):
方法一:将字符串转换为日期类型
select * from test where create_time between to_date(‘2015-03-03 17:39:05’) and to_date(‘2016-03-03 17:39:52’)
二.存储日期类型的字段为数值类型
MySql(bigint):
方法一:将日期字符串转换为时间戳
select * from test where create_time >unix_timestamp(‘2011-03-03
17:39:05’) and create_time<unix_timestamp(‘2011-03-03 17:39:52’)
方法二:将时间戳转换为日期类型
select * from test where from_unixtime(create_time/1000) between ‘2014-03-03 17:39:05’ and ‘2015-03-03 17:39:52’)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)