Jake Ball
Jake Ball

Reputation: 808

Countdown to sunday

I am currently looking at creating a script for my site that will count down to sunday of that week, every week.

Example:

The user visits the site on a saturday at 11:30am, they will be greeted with:

"The next time this page will be updated is in 0 days, 12 hours and 30 minutes."

Any ideas?

Upvotes: 1

Views: 1048

Answers (3)

user234932
user234932

Reputation:

Here's one solution:

http://jsfiddle.net/foxbunny/xBE7L/

It also automatically updates every second.

Edit: I've included the offset parameter, and you use it to supply the difference between user's and server's time-zone if necessary.

Upvotes: 1

core1024
core1024

Reputation: 1882

I am using similar to this solution in one of my pojects. You can use it like this:

ago(strtotime("next sunday")) but you need to change $difference = $now - $time; to $difference = $time - $now;

Upvotes: 2

spencercw
spencercw

Reputation: 3358

You can use this little trick to get a timestamp for midnight next Sunday:

$sunday = strtotime('next Sunday');

See this answer for how to format it into something useful. Right now I get this:

print_r(dateDifference($sunday, time()));
Array
(
    [years] => 0
    [months_total] => 0
    [months] => 0
    [days_total] => 0
    [days] => 0
    [hours_total] => 4
    [hours] => 4
    [minutes_total] => 256
    [minutes] => 16
    [seconds_total] => 15387
    [seconds] => 27
)

Upvotes: 4

Related Questions