2012-08-23 49 views
1

返回开始日期和CURENT月的结束日期我有两个参数的存储过程@startdate和@EndDatePHP的查询字符串由默认的网址

而且我有一个网址如下

的“http:// localhost/filename.php?startdate = '01 -08-2012'& enddate = '31 -08-2012'

就目前而言,每个月我都必须手动更改以获取当月的startdate和enddate 。对于例如对于九月,我将不得不改变'01 -09-2012''31 -09-2012'

我正在寻找PHP代码或函数,它会自动将每月的第一天作为开始日期和最后一天该月在URL中的结束日期?

+1

你不需要在你的查询字符串单引号的日期。你有什么尝试? – Raptor

+0

可能dublicate:http://stackoverflow.com/questions/2680501/how-can-i-find-the-first-and-last-date-in-a-month-using-php – Peon

回答

2

首先与前一个月的最后一天:

$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"; 
+0

谢谢...我什么应该写在URL? [localhost/filename.php?startdate = '01-08-2012'&enddate = '31-08-2012] – user1449596

+0

使用此代码,您无需在URL中传递任何内容。尝试一下。 – alfasin

+0

我应该用文本startdate和enddate替换文本“第一天”和“第二天”,因为我的参数是startdate和enddate。我复制并粘贴了整个代码,但它只是打印日期。 – user1449596

4

第一天:

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 

更改格式为您的需求。