如何将 MySQL 查询日期格式化为这种格式?目前我的变量是 2013 年 8 月 13 日,但在我的数据库中是 2013 年 8 月 13 日。
$sql_stmt = "select * from abs where myname = 'david' and date between '$start' and '$end' order by log_id;";
尝试:
$sql_stmt = "select * from abs where myname = 'david' and date between STR_TO_DATE('$start', '%m/%d/%Y') and STR_TO_DATE('$end', '%m/%d/%Y') order by log_id;";
您可以将输出字符串转换为可变日期格式,然后进行比较。
$sql_stmt = "select *,DATE_FORMAT(date, '%d/%c/%Y') as date1
from abs
where
myname = 'david'
and date1 between '$start' and '$end'
order by log_id;";
我们有
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
-> 'Saturday October 1997'
我们可以将您的解决方案调整为
$sql_stmt = "select * from abs where myname = 'david'
and DATE_FORMAT(date, '%W %M %Y')
between STR_TO_DATE('$start', '%m/%d/%Y')
and STR_TO_DATE('$end', '%m/%d/%Y') order by log_id;";