php判断今天是星期几并作相应操作

PQianbei 2016-01-19 12:43:31
PHP判断今天如果是星期一的话,则把查询的时间变量设置为上周五。
如果判断今天是星期二或者三或者四或者五,则查询把时间变量设置为前一天。比如说今天是星期二,则我需要查询的时间变量应该为星期一。
请教下代码如何编写。谢谢。
数据库中的日期格式为unix时间戳。
...全文
177 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
智商众筹 2016-01-19
  • 打赏
  • 举报
回复
https://www.baidu.com/s?wd=php%20星期几&rsv_spt=1&rsv_iqid=0xfe8aba740000aac2&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=3&rsv_sug1=2&rsv_sug2=0&rsv_sug7=100&inputT=2048&rsv_sug4=2048
leexiang_home 2016-01-19
  • 打赏
  • 举报
回复
function test(){ $week = date('w',time()); switch($week){ case 1: $where['time'] = strtotime('- 3 days'); break; case 2 || 3 || 4 || 5: $where['time'] = strtotime('- 1 days'); break; } return $where['time']; //返回你要的时间戳 }
lirenbing01 2016-01-19
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
$rule = array(-2, -3, -1, -1, -1, -1, -1); //你没有说星期六、星期天要怎么处理,我自作主张的给你加上了
$t = strtotime($bule[date('w'] . ' day'); //这就是你要的时间戳
//如果只要精确到日,再
$t = strtotime('Y-m-d', $t));
手滑了吧
xuzuning 2016-01-19
  • 打赏
  • 举报
回复
$rule = array(-2, -3, -1, -1, -1, -1, -1); //你没有说星期六、星期天要怎么处理,我自作主张的给你加上了
$t = strtotime($bule[date('w'] . ' day'); //这就是你要的时间戳
//如果只要精确到日,再
$t = strtotime(date('Y-m-d', $t));

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧