PHP选择每隔一个星期三 [英] PHP Select every other Wednesday

查看:111
本文介绍了PHP选择每隔一个星期三的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助从5/2/12开始选择每隔一个星期三。下面的代码从目前的一周开始每隔一个星期三选择。但是我需要设定开始一周。我熟悉PHP,但不熟悉php日期。所以请尽可能具体。
我发现这个:

I need help Select every other Wednesday starting on 5/2/12. This code below selects every other Wednesday starting on the week it currently is. But i need to set the beginning week. I am familiar with PHP, but not familiar with php dates. So please be as specific as possible. I found this:

$number_of_dates = 10;

for ($i = 0; $i < $number_of_dates; $i++) {
   echo date('m-d-Y', strtotime('Wednesday +' . ($i * 2) . ' weeks')). "<br>".PHP_EOL;
}


推荐答案

使用 mktime 创建您的开始日期和将其作为 strtotime ,以便从那里开始计数:

Use mktime to create your starting date and pass that as the second argument to strtotime so that counting starts from there:

$startDate = mktime(0, 0, 0, 5, 2, 2012); // May 2, 2012
for ($i = 0; $i < $number_of_dates; $i++) {
   $date = strtotime('Wednesday +' . ($i * 2) . ' weeks', $startDate);
   echo date('m-d-Y', $date). "<br>".PHP_EOL;
}

查看动作

这篇关于PHP选择每隔一个星期三的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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