Closed Thread Icon

Topic awaiting preservation: strtotime() sporadic? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30645" title="Pages that link to Topic awaiting preservation: strtotime() sporadic? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: strtotime() sporadic? <span class="small">(Page 1 of 1)</span>\

 
redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 11-12-2008 16:54

Hey all,

I spent most of the afternoon yesterday trying to figure out why the following code....

code:
$date = strtotime("+17 hours", strtotime(date("Y-m-d h:i:s")));
		echo date("Y-m-d", $date);

....would not display the next days date. I finally gave up on it for the night, then to my surprise found that it is working this morning (without any change). I'm more used to mktime and have just recently started playing around with strtotime, I wonder am I missing something?

twItch^
Maniac (V) Mad Scientist

From: Denver, CO, USA
Insane since: Aug 2000

posted posted 11-12-2008 18:02

man.

uh

try this:

code:
$date=strtotime('+17 hours', time());



That will display whatever date is 17 hours from now. To just display tomorrow's date...

code:
$date=strtotime('tomorrow', time());



-S

(Edited by twItch^ on 11-12-2008 18:05)

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 11-12-2008 19:48

Right,

My actual implementation is a little more complex so I just broke it down to the problem I found...

code:
date("Y-m-d h:i:s")

Could be any date... and

code:
"+17 hours"

could be any number of hours.

twItch^
Maniac (V) Mad Scientist

From: Denver, CO, USA
Insane since: Aug 2000

posted posted 11-12-2008 22:46

Well, I've never had any sporadic behavior. Just so long as you're aware +17 hours won't return tomorrow's date all the time.

Could you explain, more specifically, what sorts of behavior you're not expecting?

-S

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 11-14-2008 20:31
quote:

twItch^ said:
Just so long as you're aware +17 hours won't return tomorrow's date all the time.


Lol, yeah... It was almost a mistake that simple. In my time I'm passing lowercase 'h' (not military). So the function was assuming it was always morning. Chaning to 'H' fixed it up. That explains why it seemed sporadic, in the morning hours it was spot-on, in the afternoon it was a day behind :P

Thanks for your time twitch!

« BackwardsOnwards »

Show Forum Drop Down Menu