开发者

PHP Strtotime additional functionality

The following code returns the first saturday of next month and the first saturday of the month after. With the first saturday of next month the only issue is that it allows the user to select a day even if it is tomorrow.

Say just coming up is the 2nd of April which is a saturd开发者_JS百科ay. At the moment a customer can book this day. However If the first saturday of next month is less than 8 days again I want the first and of this month and next month to default one month along further.

<?php echo date('Y-m-d', strtotime('first saturday', strtotime('+1 month', strtotime(date("01-m-Y")))));?>

<?php echo date('Y-m-d', strtotime('first saturday', strtotime('+2 month', strtotime(date("01-m-Y")))));?>

Any ideas?


Would this work for you?

// Use 691200 for eight days.
if ((strtotime('first saturday', strtotime('+1 month')) - mktime()) < 691200) {
    // Go two months.
    echo date('Y-m-d', strtotime('first saturday', strtotime('+2 month', strtotime(date("01-m-Y")))));
    echo date('Y-m-d', strtotime('first saturday', strtotime('+3 month', strtotime(date("01-m-Y")))));
} else {
    // Go one month.
    echo date('Y-m-d', strtotime('first saturday', strtotime('+1 month', strtotime(date("01-m-Y")))));
    echo date('Y-m-d', strtotime('first saturday', strtotime('+2 month', strtotime(date("01-m-Y")))));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜