|
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?
|
|
|
|
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
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. 
|
|
|
|
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
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
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
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() 
|
|
|
|
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: <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!
|
|
|
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.
|
|
Posts: 417
Joined: November 2001
|
|
Forums63
Topics37,575
Posts293,930
Members13,823
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|