Previous Thread
Next Thread
Print Thread
Rate Thread
#268473 01/30/2004 1:35 PM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
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?

Sponsored Links
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
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.


UBB.classic: Love it or hate it, it was mine.
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
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.

Joined: May 1999
Posts: 3,039
Guru
Guru
Offline
Joined: May 1999
Posts: 3,039
strtotime() is your friend

$timestamp = echo strtotime("next Thursday 09:00 PM");

Last edited by Scream; 01/30/2004 2:50 PM.

UBB.threads Developer
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Oh wow!

Holy Bananna feathers that's easy.

Have I told you today that you're a genius? Thank you.

Sponsored Links
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
That's pretty cool. PHP still sucks.


UBB.classic: Love it or hate it, it was mine.
Joined: Oct 2003
Posts: 2,305
Old Hand
Old Hand
Joined: Oct 2003
Posts: 2,305
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";
?>

Joined: May 1999
Posts: 3,039
Guru
Guru
Offline
Joined: May 1999
Posts: 3,039
PHP Rawks! You know you're drawn to it's powers!


UBB.threads Developer
Joined: Feb 2001
Posts: 2,268
Junior Member
Junior Member
Offline
Joined: Feb 2001
Posts: 2,268
[]Charles_Capps said:
That's pretty cool. PHP still sucks. [/]

ROFLMAO!

Turn to the dark side Charles, Rick is your father!

Joined: Apr 2003
Posts: 31
User
User
Offline
Joined: Apr 2003
Posts: 31
That is easy...but wouldn't you know that is the example that the php.net manual uses for strtotime()

Sponsored Links
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
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!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)