Maison  >  Article  >  développement back-end  >  php 获取日期(当天,前天,明天,本周,本月,本季度,本年)

php 获取日期(当天,前天,明天,本周,本月,本季度,本年)

WBOY
WBOYoriginal
2016-08-08 09:31:081967parcourir

  1. $begin_day = date("Y-m-d 00:00:00");  
  2. $end_day = date("Y-m-d 23:59:59");  
  3.   
  4. $last_begin = date("Y-m-d 00:00:00",strtotime("last days"));  
  5. $last_end = date("Y-m-d 23:59:59",strtotime("last days"));  
  6.   
  7. $next_begin = date("Y-m-d 00:00:00",strtotime("next days"));  
  8. $next_end = date("Y-m-d 23:59:59",strtotime("next days"));  
  9.   
  10. $month_times = strtotime(date("Y-m"));  
  11. $monthday = date("t");  
  12. $month = date("n");  
  13. $begin_this_week=date("Y-m-d 00:00:00",strtotime("last Sunday +1 day"));  
  14. $end_this_week=date("Y-m-d 23:59:59",strtotime("next Sunday"));  
  15.   
  16. $begin_this_month=date('Y-m-01 00:00:00');  
  17. $end_this_month=date("Y-m-$monthday 23:59:59",strtotime("this month",$month_times));  
  18.   
  19. if($month==1 || $month==2 ||$month==3){  
  20.  $begin_this_quarter=date('Y-01-01 00:00:00');  
  21.  $end_this_quarter=date("Y-03-31 23:59:59");  
  22. }elseif($month==4 || $month==5 ||$month==6){  
  23.  $begin_this_quarter=date('Y-04-01 00:00:00');  
  24.  $end_this_quarter=date("Y-06-30 23:59:59");      
  25. }elseif($month==7 || $month==8 ||$month==9){  
  26.  $begin_this_quarter=date('Y-07-01 00:00:00');  
  27.  $end_this_quarter=date("Y-09-30 23:59:59");      
  28. }else{  
  29.  $begin_this_quarter=date('Y-10-01 00:00:00');  
  30.  $end_this_quarter=date("Y-12-31 23:59:59");          
  31. }  
  32.   
  33. $begin_this_year=date('Y-01-01 00:00:00');  
  34. $end_this_year=date('Y-12-31 23:59:59');  
  35.   
  36. //一季度是1月1日到3月31日;二季度是4月1日到6月30;三季度是7月1到9月30;四季度是10月1到12月31  
  37. echo "当天 | ";  
  38. echo "前天 | ";  
  39. echo "明天 | ";  
  40. echo "本周 | ";  
  41. echo "本月 | ";  
  42. echo "本季度 | ";  
  43. echo "本年  "

以上就介绍了php 获取日期(当天,前天,明天,本周,本月,本季度,本年),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn