2012-10-31 217 views
0

我使用这样的代码来捕获与时间相关的记录。使用时间戳比较mysql日期

这里是一个SQL片段...使用格式dd/mm/YYYY被输入

$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')))); 

日期和使用转换的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

尝试:

echo date('Y-m-d H:i:s',strtotime(str_replace('/','-','25/11/2011 00:00:00'))); 

的 “H” 装置12小时格式, “H” 装置24小时格式

+0

这似乎已经解决了这个问题!感谢 –

+0

很高兴提供帮助 - 如果您满意,您能接受答案吗? – FreudianSlip