php querystring在url中默认返回当前月份的开始日期和结束日期


php querystring to return startdate and enddate of curent month by Default in url

我有一个存储过程,它有两个参数@startdate和@enddate

我有一个URL如下

'http://localhost/filename.php?startdate='01-08-2012'&结束日期='31-08-2012'

按照目前的情况,每个月我都必须手动更改,以获得当前月份的开始日期和结束日期。例如,对于9月份,我将不得不更改"2012年9月1日"2012年09月31日"

我正在寻找php代码或函数,它会自动将每个月的第一天作为起始日期,并将该月的最后一天作为url中的结束日期?

第一天:

date('Y-m-01'); //current year and month

最后一天:

date("Y-m-t"); //current year and month and t means the last day of this month

根据需要更改格式。

上个月的第一天和最后一天:

$current_year = date('Y');
$current_month = date('m');
$lastdateofmonth = date('t', $current_month);
$startdate = "01-$current_month-$current_year";
$enddate = "$lastdateofmonth-$current_month-$current_year";