Forum Moderators: coopster

Message Too Old, No Replies

strtotime() not working today

         

mgm_03

1:30 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



Can someone tell me what you get from this snippet:

<?php
$current = date ("F", strtotime("now"));

$next = date("F", strtotime("next month")); //or try "+1 month"

echo $current.'...'.$next;
?>

My site is launching today and I get August , October. Yesterday it worked correctly. Could this be a bug in the function?

bunkermaster

2:00 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



Yep it's showing october for me too
I tried the following:
$next2 = date("F", strtotime("+1 month"));
same result

$next3 = date("F", strtotime("+0 month"));
returns August... go figure.

Edit
$next2 = date("F", strtotime("+2 month"));
returns October too hehe

dcrombie

2:42 pm on Aug 31, 2005 (gmt 0)



"today" is 31 August
"+1 month" or "next month" is then 31 September, which actually gives you 1 October

Also strtotime("now") can be replaced with time(), or left out entirely in the date command.

;)

bunkermaster

2:43 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



Check the timestamp returned by next month, it's not really october first :)

dcrombie

2:51 pm on Aug 31, 2005 (gmt 0)



Yes, you're right. "first month" is the next month, while "next month" is the one after the "first".
I remember going through that learning curve a while back ;)

Here's a reference:
[bugs.php.net...]

mgm_03

2:58 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



thanks for the replies...I decided to go a more reliable route....

function makeDropDown() {
$months = array("1"=>"January", "2"=>"February", "3"=>"March", "4"=>"April", "5"=>"May", "6"=>"June", "7"=>"July", "8"=>"August", "9"=>"September", "10"=>"October", "11"=>"November", "12"=>"December");

$cur_index = date ("n", strtotime("now"));
$current = $months["$cur_index"];

$next_index = ($cur_index == '12')? '1' : $cur_index + 1;
$next = $months["$next_index"];

$form = '<div><form method="get" action="'.$_SERVER['PHP_SELF'].'" name="form1">
Show all events scheduled for &nbsp;&nbsp;<select name="month" onchange="form1.submit()">
<option value="">Select a Month</option>
<option value="'.$current.'">'.$current.'</option>
<option value="'.$next.'">'.$next.'</option>
</select><p></p></div>';
return $form;

}

[edited by: jatar_k at 4:59 pm (utc) on Aug. 31, 2005]
[edit reason] fixed sidescroll [/edit]

coopster

3:41 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I remembered that discussion, dcrombie ;)

getdate this and next month [webmasterworld.com]
getdate this and next month etc. [webmasterworld.com]