Jump to content

echo date and time of upcoming event


samoht

Recommended Posts


$nextWeek = time() + (7 * 24 * 60 * 60);
                   // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:       '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():

echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) . ' 10:45AM';

voip03, that would output today's date and the date in a week's time.

use the example to write the code

Your example says nothing about "saturday" at all, the example does not pertain to the question that was asked.

 

OP: The strtotime solution is the best one, however, as he said, strtotime is a tricky beast.  You may want to use:

strtotime('+1 saturday')

 

-Dan

Thanks Guru!

 

I thought it would be more complicated.

What is the tricky stuff with strtotime() ?

Adam's name is Adam, his title is Guru ;-)

 

The tricky stuff comes from the interpretations of "next" and "last".  For instance, if I ask for "next wednesday" I get 7 days from now.  If I ask for "thursday" or "next thursday" I get tomorrow.  The definition of "next" for the computer is "the next occurring one."  The definition of "next" in common parlance is "the one during next week."  Sometimes strtotime produces results you don't expect, so I'd test this for a week's worth of days to make sure it always returns the right dates before releasing it.

 

-Dan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.