Home  >  Article  >  Backend Development  >  php get date (today, day before yesterday, tomorrow, this week, this month, this quarter, this year)

php get date (today, day before yesterday, tomorrow, this week, this month, this quarter, this year)

WBOY
WBOYOriginal
2016-08-08 09:31:081964browse

  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教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn