4

这是我的日期数据;从 : 09-01-2013 到 : 22-01-2013 (格式固定)

如何将列日期格式化为send_date_time..d-m-Y以下是我的查询:

$filter = "and DATE_FORMAT(send_date_time,'%d-%m-%Y') BETWEEN '08-01-2012 12:00:00' and '22-01-2013 12:00:00' ";

但是当我尝试使用这个(下面)查询时,上面的查询失败了,是的可以工作:

$filter = "and send_date_time BETWEEN '2013-01-08 12:00:00' and '2013-01-22 12:00:00' ";

完整查询

$get_transaction_history  = ("select * from `sms_sendlog` where store_id='".$store."' ".$filter." order by id desc"); 

柱子:

Colum Name : send_date_time
e.g  value : 2012-10-22 10:19:36
4

2 回答 2

5

它应该像

$filter = "and send_date_time BETWEEN DATE_FORMAT('08-01-2012 12:00:00','%d-%m-%Y') AND DATE_FORMAT('22-01-2013 12:00:00','%d-%m-%Y') ";

阅读更多

于 2013-01-09T05:45:41.830 回答
0

使用STR_TO_DATE函数而不是使用DATE_FORMAT函数。

试试这个:

$filter = "and send_date_time BETWEEN STR_TO_DATE('08-01-2012 12:00:00','%d-%m-%Y') AND STR_TO_DATE('22-01-2013 12:00:00','%d-%m-%Y') ";

检查此链接MySQL 日期时间函数:STR_TO_DATE

于 2013-01-09T07:05:51.193 回答