【问题标题】:php querystring to return startdate and enddate of curent month by Default in urlphp查询字符串默认返回当前月份的开始日期和结束日期在url中
【发布时间】:2012-08-23 07:10:45
【问题描述】:

我有一个带有两个参数@startdate 和@enddate 的存储过程

我有一个如下网址

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

就目前而言,每个月我都必须手动更改它以获取当前月份的开始日期和结束日期。例如对于 9 月,我将不得不更改 '01-09-2012' '31-09-2012'

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

【问题讨论】:

标签: php


【解决方案1】:

第一天:

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

根据需要更改格式。

【讨论】:

    【解决方案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";
    

    【讨论】:

    • 谢谢...我应该在 url 中写什么? [localhost/filename.php?startdate='01-08-2012'&enddate='31-08-2012]
    • 使用此代码,您无需在 URL 中传递任何内容。试试看。
    • 我应该用文本 startdate 和 enddate 替换你的文本“第一天”和“第二天”,因为我的参数是 startdate 和 enddate。我复制并粘贴了您的整个代码,但它只是打印日期。
    • 我更改了代码,现在它将设置您需要的参数(开始日期,结束日期)。如果您向我展示您的代码以及您期望的输出结果会更容易。
    • 现在可以了。非常感谢..因为我是编码新手..我无法轻松理解..我只是不知道添加 $startdate 和 $enddate。在您为我更改后,它起作用了。
    猜你喜欢
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多