开发者

How can I show next Wednesday's date using php

开发者 https://www.devze.com 2023-03-30 21:24 出处:网络
If today is Wednesday, I need to show next Wednesday\'s date. If today is Tuesday, I n开发者_如何转开发eed to show tomorrows date.Use strtotime to calculate the time and date to format it:

If today is Wednesday, I need to show next Wednesday's date. If today is Tuesday, I n开发者_如何转开发eed to show tomorrows date.


Use strtotime to calculate the time and date to format it:

echo date('Y-n-d', strtotime('next Wednesday'));


An option is to use strtotime() to get the Unix timestamp for the date, then output it in a nice format with date().

echo date('Y-m-d', strtotime("next Wednesday"));

Aside from strtotime(), there is also the DateTime class available.

$wednesday = new DateTime('next Wednesday');
echo $wednesday->format('Y-m-d');
// or
echo date_format(date_create('next Wednesday'), 'Y-m-d');

Using DateTime is much more flexible, if you might be needing far future dates (not that next Wednesday is far future!) or further modification of the date.


Just wanted to add to the other helpful answers. If you wanted not next Wednesday but the Wednesday after, you'd do this:

echo date('Ymd', strtotime('+2 week Wednesday'))


Very easy, using strtotime:

 echo strtotime("next Wednesday");
0

精彩评论

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