- 论坛徽章:
- 1
|
原帖由 lip199162 于 2007-7-15 15:55 发表
php日期计算
在程序过程中,要求对日期进行如下计算:
随便给定一个日期(格式为 YYYY-mm-dd) 计算出此日所在周的第一天和最后一天的日期,输出格式为 YYYY-mm-dd
随便给定一个日期(格式为 YYYY ...
- function w_fl($i_date)
- {
- $w_last=date("Y-m-d",strtotime("Sunday",strtotime($i_date)));
- return array(
- date("Y-m-d",strtotime("-6 days",strtotime($w_last))),
- $w_last
- );
- }
- function m_fl($i_date)
- {
- $m_first=date("Y-m-01",strtotime($i_date));
- return array(
- $m_first,
- date("Y-m-d",strtotime("+1 month -1day",strtotime($m_first)))
- );
- }
- for($i=1; $i<31; $i++){
- $i_date = date("Y-m-$i");
- print_r($i_date."\n");
- print_r(w_fl($i_date));
- print_r(m_fl($i_date));
- echo(str_repeat("=",32)."\n");
- }
复制代码 |
|