【发布时间】:2011-09-26 18:44:26
【问题描述】:
使用 PHP 和 MySQL 并想使用 SELECT 语句,其中 date_post(datetime 变量) 从上个月的最后一个日期开始到下个月的第一天,请帮帮我。
提前谢谢你。
my database: 'id', 'content', 'image', 'date_post',
等等。我尝试使用
$today = getdate();
$thisyear=$today['year'];
$thismon=$today['mon'];
$date_start=$thisyear.'-'.$thismon.'-01';
$date_end=$thisyear.'-'.($thismon+1).'-01';
$sql="SELECT *, DATE_FORMAT(date_post, '%d-%m-%Y') AS datepost
FROM my_table
WHERE date_post BETWEEN date('$date_start')
AND date('$date_end')
ORDER BY date_post DESC";
【问题讨论】:
-
请提供有关您的数据库架构的一些详细信息,以及您尝试过的任何现有 SQL。
-
我的数据库:'id'、'content'、'image'、'date_post'等,我尝试使用 $today = getdate(); $thisyear=$today['年份']; $thismon=$today['mon']; $date_start=$thisyear.'-'.$thismon.'-01'; $date_end=$thisyear.'-'.($thismon+1).'-01'; $sql="SELECT *, DATE_FORMAT(date_post, '%d-%m-%Y') AS datepost FROM my_table WHERE date_post BETWEEN date('$date_start') AND date('$date_end') ORDER BY date_post DESC";