我认为我的工作非常好,然后意识到今天是一个复杂的特殊月份。
这就是我所拥有的:
<!-- determines first Wednesday and first Thursday of the month to echo something different than the rest of the days of the month. -->
<?php
$firstwed = strtotime("first Wednesday, first Thursday". date("F Y"));
$now = strtotime('today');
if( $firstwed == $now) {
echo "Registration is closed until our next event!";
// do something
} else {
echo 'REGISTER AND PAY ONLINE HERE';
// do something else
}
?>
但我昨天也需要它(星期三,但它恰好是上个月)。
如果我今天(星期四)定位,它似乎甚至无法正常工作。??
基本上,故事是,每个月的每个星期五,他们都开会,需要注册才能在周三和周四关闭;然后在周五重新开放。
请帮助并非常感谢你!
*编辑:其他人可以帮助解决这个问题吗?我还没有取得任何进展。
答案 0 :(得分:1)
你的问题很难理解,
如果我理解正确,
这里是增强版本,有一些简化: -
$today = explode(',', date('d,D,t')); // month day, week day, days in month
switch ($today[1])
{
case "Wed":
if (($today[0]+2 > $today[2]) || $today[0] <=7)
{
//closed
}
case "Thu":
if (($today[0]+1 > $today[2]) || $today[0] <=7)
{
//closed
}
break;
}
因为无论如何,第一个周三/周四的月日将永远不会超过7
答案 1 :(得分:1)
您的版本实际上是在比较周二的第二天:
php > echo date('c', strtotime('first wednesday, first thursday'));
2011-12-08T00:00:00-06:00 <--- dec 8th = thursday, but not **THE** first thursday
php > echo date('c', strtotime('first wednesday'));
2011-12-07T00:00:00-06:00 <--- dec 7th = wednesday
php > echo date('c', strtotime('today'));
2011-12-01T00:00:00-06:00 <-- dec 1st = thursday <-- actual first thursday of the emonth
strtotime很擅长猜测你想要什么,但它并不是绝对可靠的,而且这是它在你脸上爆炸的情况之一。它发现今天发生的“第一个星期四”,而不是本月的第一个星期四。
php > echo date('c', strtotime('first thursday december'));
2011-12-08T00:00:00-06:00
php > echo date('c', strtotime('thursday december'));
2011-12-01T00:00:00-06:00
php > echo date('c', strtotime('thursday'));
2011-12-01T00:00:00-06:00
不是特别直观。
您最好使用正式的DateTime调用来获取当月FIRST当天的“星期几”,并查看它是否为星期四/星期四。