开发者

Number of seconds from now() to Sunday midnight [duplicate]

开发者 https://www.devze.com 2023-02-04 22:11 出处:网络
This question already has answers here: Get interval seconds between two datetime in PHP? 开发者_开发百科
This question already has answers here: Get interval seconds between two datetime in PHP? 开发者_开发百科 (8 answers) Closed 12 months ago.

In PHP how do I get the number of seconds from now() until the next Sunday at midnight?

I don't want the solution relative to a specific date, but just to the next Sunday.


$seconds = strtotime('next Sunday') - time();


You can use

print strtotime('next Sunday') - time();


Try this:

function secs_until() {
  $now = time();
  $next = strtotime("next Sunday midnight");
  return $next - $now;
}


It's as simple as:

strtotime('next Sunday') - time()


$seconds = mktime(0,0,0, date("n"), date("j") + (7 - date("N")), date("Y")) - time();

That string will give you the diff in seconds from now to sunday morning at 12:00. You can adjust the first 3 arguments in mktime() to give you a variable time of day (say 8:45 AM)

0

精彩评论

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