php 得到上周,本周,上月,本月,本季度,上季度

Php代码  网站推广
  1. <?php  
  2. echo date("Ymd",strtotime("now")), "\n";  
  3. echo date("Ymd",strtotime("-1 week Monday")), "\n";  
  4. echo date("Ymd",strtotime("-1 week Sunday")), "\n";  
  5. echo date("Ymd",strtotime("+0 week Monday")), "\n";  
  6. echo date("Ymd",strtotime("+0 week Sunday")), "\n";  
  7.   
  8. echo "*********第几个月:";  
  9. echo date('n');   
  10. echo "*********本周周几:";  
  11. echo date("w");   
  12. echo "*********本月天数:";  
  13. echo date("t");  
  14. echo "*********";  
  15.   
  16. echo '<br>上周:<br>';  
  17. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";  
  18. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";  
  19. echo '<br>本周:<br>';  
  20. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";  
  21. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";  
  22.   
  23. echo '<br>上月:<br>';  
  24. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";  
  25. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";  
  26. echo '<br>本月:<br>';  
  27. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";  
  28. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";  
  29.    
  30. $season = ceil((date('n'))/3);//当月是第几季度  
  31. echo '<br>本季度:<br>';  
  32. echo date('Y-m-d H:i:s'mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";  
  33. echo date('Y-m-d H:i:s'mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";  
  34.    
  35. $season = ceil((date('n'))/3)-1;//上季度是第几季度  
  36. echo '<br>上季度:<br>';  
  37. echo date('Y-m-d H:i:s'mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";  
  38. echo date('Y-m-d H:i:s'mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";   
  39. ?>  
  40.    
  41. php两个日期相减得天数  
  42. <?php  
  43. function count_days($a,$b){  
  44.  $a_dt=getdate($a);  
  45.  $b_dt=getdate($b);  
  46.  $a_new=mktime(12,0,0,$a_dt['mon'],$a_dt['mday'],$a_dt['year']);  
  47.  $b_new=mktime(12,0,0,$b_dt['mon'],$b_dt['mday'],$b_dt['year']);  
  48.  return round(abs($a_new-$b_new)/3600/24);  
  49. }  
  50.     function count_days($formdate,$todate){  
  51.         return round(abs(strtotime($formdate)-strtotime($todate))/3600/24);  
  52.     }  (fblww-0105)

你可能感兴趣的:(php 得到上周,本周,上月,本月,本季度,上季度)