5

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.

freshest
  • 6,229
  • 9
  • 35
  • 38

5 Answers5

19
$seconds = strtotime('next Sunday') - time();
Vinicius Braz Pinto
  • 8,209
  • 3
  • 42
  • 60
7

You can use

print strtotime('next Sunday') - time();
Matt Lowden
  • 2,586
  • 17
  • 19
5

Try this:

function secs_until() {
  $now = time();
  $next = strtotime("next Sunday midnight");
  return $next - $now;
}
fire
  • 21,383
  • 17
  • 79
  • 114
3

It's as simple as:

strtotime('next Sunday') - time()
Matt
  • 1,412
  • 3
  • 15
  • 18
2
$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)

Geoffrey Wagner
  • 818
  • 1
  • 5
  • 11