PHP 如何获取两个时间之间的年和月份及间隔天数 PHP两个日期之间的所有日期

[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $time1 = strtotime('2014-02-04'); // 自动为00:00:00 时分秒 两个时间之间的年和月份  
  2. $time2 = strtotime('2015-02-06');  
  3.    
  4. $monarr = array();  
  5. $monarr[] = '2014-02'// 当前月;  
  6. while( ($time1 = strtotime('+1 month'$time1)) <= $time2){  
  7.       $monarr[] = date('Y-m',$time1); // 取得递增月;   
  8. }  
  9.    
  10. print_r($monarr);  


[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?php  
  2. //今天与2008年9月9日相差多少天  
  3. $Date_1 = date("Y-m-d");  
  4. $Date_2 = "2008-10-11";  
  5. $d1 = strtotime($Date_1);  
  6. $d2 = strtotime($Date_2);  
  7. $Days = round(($d2-$d1)/3600/24);  
  8. echo "今天与2008年10月11日相差" . $Days . "天";  
  9. ?>  

[php]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?php  
  2. function prDates($start,$end){ // 两个日期之间的所有日期  
  3.     $dt_start = strtotime($start);  
  4.     $dt_end = strtotime($end);  
  5.     while ($dt_start<=$dt_end){  
  6.         echo date('Y-m-d',$dt_start)."\n";  
  7.         $dt_start = strtotime('+1 day',$dt_start);  
  8.     }  
  9. }  
  10. prDates('2005-02-01','2005-02-05');  
  11.   
  12. ?>  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值