UBB.Dev
Posted By: JoshPet Automatic Future Date - 01/30/2004 8:35 PM
OK - here's a puzzle that I'm not sure how to do.

I want to grab the epoch time for whatever the next thursday is at 9PM.

So if today is 1/30/04 I want it to know that the next thursday is 2/5

Once it gets to 2/6, I want to know it's 2/12.

I know how to add time to the current time, but how can I know what the date is for an upcoming thursday?
Posted By: Charles Capps Re: Automatic Future Date - 01/30/2004 8:40 PM
Immediate thought...

date('w') will return the day of the week. Compare that to the desired day, then multiply the difference by 60 * 60 * 24 to get what must be added to get "now" on that day.

Similar date() based math can then be used to determine how many seconds must be deleted to get to midnight (get hours, subtract, get minutes, subtract, get seconds, subtract), then add 60 * 60 * 21 to get 9 PM.
Posted By: JoshPet Re: Automatic Future Date - 01/30/2004 9:21 PM
Oh that's a good idea. Just cycle ahead the next 7 days until you find thursday, then I've got my thursday point of reference.

Thanks.
Posted By: Rick Re: Automatic Future Date - 01/30/2004 9:49 PM
strtotime() is your friend

$timestamp = echo strtotime("next Thursday 09:00 PM");
Posted By: JoshPet Re: Automatic Future Date - 01/30/2004 11:15 PM
Oh wow!

Holy Bananna feathers that's easy.

Have I told you today that you're a genius? Thank you.
Posted By: Charles Capps Re: Automatic Future Date - 01/31/2004 2:28 AM
That's pretty cool. PHP still sucks.
Posted By: scroungr Re: Automatic Future Date - 01/31/2004 3:52 AM
other examples

<?php
echo strtotime ("now"), "\n";
echo strtotime ("10 September 2000"), "\n";
echo strtotime ("+1 day"), "\n";
echo strtotime ("+1 week"), "\n";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime ("next Thursday"), "\n";
echo strtotime ("last Monday"), "\n";
?>
Posted By: Rick Re: Automatic Future Date - 01/31/2004 7:03 AM
PHP Rawks! You know you're drawn to it's powers!
Posted By: Dalantech Re: Automatic Future Date - 01/31/2004 7:00 PM
[]Charles_Capps said:
That's pretty cool. PHP still sucks. [/]

ROFLMAO!

Turn to the dark side Charles, Rick is your father!
Posted By: Jelly_Donut Re: Automatic Future Date - 02/05/2004 3:22 AM
That is easy...but wouldn't you know that is the example that the php.net manual uses for strtotime()
Posted By: JoshPet Re: Automatic Future Date - 03/31/2004 10:34 AM
OK - this works great - BUT there's an oddity that I can't seem to find:

This is my code snippit:

Code
<br />	$hearinglist = "<select name=\"hearing\" class=\"formboxes\">";<br />	$count = 0;<br />	$firstdate = strtotime("this Monday 09:00 PM");<br />		$hearinglist .= "<option value=\"\">Select a Date...</option>";<br />		while ($count < 10) {<br />			$firstdatenew = date("l, F j,Y h:i A",$firstdate);<br />			$hearinglist .= "<option value=\"$firstdate\">$firstdatenew</option>";<br />			$firstdate = $firstdate + 604800;<br />			$count++;<br />		}	<br />	$hearinglist .= "</select>";	<br />


Which makes a pull down menu of the next 10 mondays at 9:PM

Although - when you view it, it shows a time of 10PM.

I got around this by requesting "this monday at 08:00 PM" but I was curious if there's a flag I need to daylight savings time or something.

Thanks!
© UBB.Developers