[英]comparing mysql dates using timestamps
I am using code like this to capture time related records. 我正在使用这样的代码来捕获与时间相关的记录。
Here is a sql fragment ... 这是一个SQL片段...
$SQL_p .= " and UNIX_TIMESTAMP(".$data['task_filter'].") >= " .
strtotime(date('Y-m-d h:i:s',strtotime(str_replace('/','-',$data['datepicker'].' 00:00:00'))));
$SQL_p .= " and UNIX_TIMESTAMP(".$data['task_filter'].") <= " .
strtotime(date('Y-m-d h:i:s',strtotime(str_replace('/','-',$data['datepicker2'].' 23:59:59'))));
Dates are entered using the format dd/mm/YYYY
and converted using str_replace('/','-',$data['datepicker2'])
where $data['datepicker2']
is the var holding the date 使用dd/mm/YYYY
格式输入日期,并使用str_replace('/','-',$data['datepicker2'])
,其中$data['datepicker2']
是保存日期的var
Using php5 on the command line for testing, when I enter .... 输入...时,在命令行上使用php5进行测试。
echo date('Y-m-d h:i:s',strtotime(str_replace('/','-','25/11/2011 00:00:00')));
I get 2011-11-25 12:00:00
BUT what I expect is 2011-11-25 00:00:00
我得到2011-11-25 12:00:00
但我期望的是2011-11-25 00:00:00
Also 也
echo date('Y-m-d h:i:s',strtotime(str_replace('/','-','25/11/2011 23:59:59')));
returns 2011-11-25 11:59:59
NOT the expected 2011-11-25 23:59:59
. 返回2011-11-25 11:59:59
不是预期的2011-11-25 23:59:59
。
What am I doing wrong ? 我究竟做错了什么 ?
Try: 尝试:
echo date('Y-m-d H:i:s',strtotime(str_replace('/','-','25/11/2011 00:00:00')));
The "h" means 12 hour format, "H" means 24 hour format “ h”表示12小时格式,“ H”表示24小时格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.