我正在使用这样的代码来捕获与时间相关的记录。
这是一个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'))));
使用dd/mm/YYYY
格式输入日期,并使用str_replace('/','-',$data['datepicker2'])
进行转换,其中$data['datepicker2']
是保存日期的var
在命令行上使用php5进行测试,当我输入....
echo date('Y-m-d h:i:s',strtotime(str_replace('/','-','25/11/2011 00:00:00')));
我得到2011-11-25 12:00:00
但我期望的是2011-11-25 00:00:00
另外
echo date('Y-m-d h:i:s',strtotime(str_replace('/','-','25/11/2011 23:59:59')));
返回2011-11-25 11:59:59
而不是预期的2011-11-25 23:59:59
。
我做错了什么?
答案 0 :(得分:0)
尝试:
echo date('Y-m-d H:i:s',strtotime(str_replace('/','-','25/11/2011 00:00:00')));
“h”表示12小时格式,“H”表示24小时格式