如何使用PHP从日期中查找星期几? [英] How to find the date of a day of the week from a date using PHP?

查看:82
本文介绍了如何使用PHP从日期中查找星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有$date YYYY-mm-dd并想获取YYYY-mm-dd所在的一周中的特定$day(由0(星期日)至6(星期六)指定).

If I've got a $date YYYY-mm-dd and want to get a specific $day (specified by 0 (sunday) to 6 (saturday)) of the week that YYYY-mm-dd is in.

例如,如果我将2012-10-11设置为$date,将5设置为$day,则我想获得2012-10-12,如果我将0设置为$day2012-10-14

For example, if I got 2012-10-11 as $date and 5 as $day, I want to get 2012-10-12, if I've got 0 as $day, 2012-10-14


你们大多数人都误解了.我有个日期$date,想得到由$date在同一周的0-6指定的日期.


Most of you misunderstood it. I got some date, $date and want to get a day specified by 0-6 of the same week $date is in.

所以不,我不想$date的日子...

So no, I don't want the day of $date...

推荐答案

我认为这就是您想要的.

I think this is what you want.

$dayofweek = date('w', strtotime($date));
$result    = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));

这篇关于如何使用PHP从日期中查找星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆