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

php中文网
发布: 2016-08-08 09:31:08
原创
2267人浏览过

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

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号