views:

115

answers:

4

I'm trying to make a PHP script to find the next occurence of a date (say 5-1). However, if I put that into strtotime() on 5-2 it comes up with the date from this year. I simply want to make it always return the next date possible. How can I make this work? I'm using codeigniter if that helps.

EDIT: Here's some code I came up with, if some humble soul runs across the same problem:

if (strtotime($date) < strtotime("now")) {
    $realseconds = strtotime($date) + 31556926; //add one year in seconds
} else {
    $realseconds = strtotime($date);
}
+1  A: 

What is 5-1 or 5-2?!

Try doing this instead:

strtotime('next October');
Alix Axel
You would think that would work, but unfortunately it doesn't. strtotime returns false.
Reactor5
+2  A: 

You could check whether the date returned is earlier than the current time, and, if it is, add one year to it.

You could also pass some date in the next year as the second parameter to strtotime.

SLaks
+1  A: 

Assuming 5-2 means february fifth, you could do

strtotime("february 5 +1 year")
Pekka
A: 

Code:

$x=strtotime($inputString);
$YEAR=60*60*24*30*12;
while($x<$time()) $x+=$YEAR;

Basically, it adds one year if the date returned by strtotime is in the past... because i used while() it will never return a date in tha past even if it was explicitly stated like that

Quamis