PHP获取本周上周,本月上月的日期
以每周的周一为第一天,周日为最后一天计算,代码如下:
//本周的日期 $rsdate = array(); $time = time(); $year = date('Y',$time); $week = date('w',$time); $month = date('m',$time); $day = date('d',$time); $rsdate = array(); if($week == 0){ // 当天为周日 $rsdate[] = date('Y-m-d', ($time - (($week == 0 ? 7 : $week) - 1) * 24 * 3600)); $rsdate[] = date("Y-m-d", $time); }else{ $rsdate[] = date ( "Y-m-d", mktime ( 0, 0, 0, $month, $day - $week + 1, $year ) ); $rsdate[] = date ( "Y-m-d", mktime ( 23, 59, 59, $month, $day - $week + 7, $year ) ); }
//上周的日期 $rsdate = array(); $time = time(); $year = date('Y',$time); $week = date('w',$time); $month = date('m',$time); $day = date('d',$time); $rsdate = array(); if($week == 0){ // 当天为周日 $rsdate[] = date('Y-m-d', ($time - (($week == 0 ? 14 : $week) - 1) * 24 * 3600)); $rsdate[] = date('Y-m-d', ($time - (($week == 0 ? 8 : $week) - 1) * 24 * 3600)); }else{ $rsdate[] = date ( "Y-m-d", mktime ( 0, 0, 0, $month, $day - $week + 1 - 7, $year ) ); $rsdate[] = date ( "Y-m-d", mktime ( 23, 59, 59, $month, $day - $week + 7 - 7, $year ) ); }
//本月的日期 $rsdate = array(); $rsdate [] = date ( "Y-m-d", mktime ( 0, 0, 0, date ( "m" ), 1, date ( "Y" ) ) ); $rsdate [] = date ( "Y-m-d", mktime ( 23, 59, 59, date ( "m" ), date ( "t" ), date ( "Y" ) ) );
//上月的日期 $rsdate = array(); $rsdate [] = date ( "Y-m-d", mktime ( 0, 0, 0, date ( "m" ) - 1, 1, date ( "Y" ) ) ); $rsdate [] = date ( "Y-m-d", mktime ( 23, 59, 59, date ( "m" ), 0, date ( "Y" ) ) );
希望对看到的朋友们有帮助!
一、推荐使用迅雷或快车等多线程下载软件下载本站资源。
二、未登录会员无法下载,登录后可获得更多便利功能,若未注册,请先注册。
三、如果服务器暂不能下载请稍后重试!总是不能下载,请点我报错 ,谢谢合作!
四、本站大部分资源是网上搜集或私下交流学习之用,任何涉及商业盈利目的均不得使用,否则产生的一切后果将由您自己承担!本站将不对任何资源负法律责任.如果您发现本站有部分资源侵害了您的权益,请速与我们联系,我们将尽快处理.
五、如有其他问题,请加网站设计交流群(点击这里查看交流群 )进行交流。
六、如需转载本站资源,请注明转载来自并附带链接
七、本站部分资源为加密压缩文件,统一解压密码为:www.aizhanzhe.com
大家评论
站长推荐
点击排行
- 1CSS控制文字在Div最底部显示
- 2Thinkphp5如何配置IP+端口访问项目模块
- 3elementUI el-dialog弹框居中
- 4教你如何搭建及优化站点
- 5国内互联网视频行业运营分析
- 6CSS实现悬浮顶部的Div工具栏
- 7记一次Thinkphp5.1框架mysql数据库崩溃(SQLSTATE [08004] Too many connections)
- 8service mysql start出错,mysql不能启动,解决mysql: unrecognized service错误
- 9连接SQL Server数据库提示:Login failed for user 'sa'错误的解决方案
- 10Thinkphp3.2在centos7上设置计划任务的方法