2009-12-24 59 views
0

我正在尝试使PHP脚本来查找下一个日期的发生(比如5-1)。但是,如果我把它放在strtotime()在5-2它从今年的日期。我只是想让它始终返回下一个可能的日子。我该如何做这项工作?如果有帮助,我使用codeigniter。使strtotime()仅在未来生成时间

编辑:下面是一些代码,我想出了,如果有些卑微的灵魂在同样的问题上运行:

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

回答

2

你可以检查返回的日期是否比当前时间早,并且,如果是,一年添加到它。

您也可以在下一年通过某个日期作为strtotime的第二个参数。

1

什么是5-15-2?!

尝试这样做,而不是:

strtotime('next October'); 
+0

你会认为这会起作用,但不幸的是它没有。 strtotime返回false。 – 2009-12-26 16:24:33

1

假设5-2指二月五日,你可以做

strtotime("february 5 +1 year") 
0

代码:

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

基本上,它增加了1年不通过的strtotime返回的日期是在过去...因为我用while()它永远不会返回过去的某个日期,即使它是这样明确表示的