neobolt Posted May 1, 2013 Share Posted May 1, 2013 I've been messing with this for a while now.I know I'm missing something simple.A user select a link which provides a 2 digit month code in the url.Example: website.com?month=04My Code: $selection_month = $_GET["month"]; $month = date('F', strtotime($selection_month)); echo "Tasks Due for the month of $month"; Month always shows up as December. Should show as April for this example.What am I missing?ThanksJohn Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 strtotime needs a datetime string try mktime(0,0,0,$selection_month,1) instead Quote Link to comment Share on other sites More sharing options...
neobolt Posted May 1, 2013 Author Share Posted May 1, 2013 Thanks Barand,This gave me a really long digit as a number.I went with an if, elseif statement as a fix instead. if ($selection_month == '01') { $month = 'January'; } elseif ($selection_month == '02') { $month = 'February'; } elseif ($selection_month == '03') { $month = 'March'; } elseif ($selection_month == '04') { $month = 'April'; } elseif ($selection_month == '05') { $month = 'May'; } elseif ($selection_month == '06') { $month = 'June'; } elseif ($selection_month == '07') { $month = 'July'; } elseif ($selection_month == '08') { $month = 'August'; } elseif ($selection_month == '09') { $month = 'September'; } elseif ($selection_month == '10') { $month = 'October'; } elseif ($selection_month == '11') { $month = 'November'; } elseif ($selection_month == '12') { $month = 'December'; } Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 $selected_month = '04'; echo date('F', mktime(0,0,0,$selected_month,1)); // --> April Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 1, 2013 Share Posted May 1, 2013 Thanks Barand, This gave me a really long digit as a number. What was your code? Because that's what strtotime does. You have to still use the date() function you were using. Quote Link to comment Share on other sites More sharing options...
neobolt Posted May 1, 2013 Author Share Posted May 1, 2013 $selected_month = '04'; echo date('F', mktime(0,0,0,$selected_month,1)); // --> April My url= http://sanitationhq.com/due-month.php?month=04 $selection_month = $_GET["month"]; $month = date('F', mktime(0,0,0,$selected_month,1)); echo "$month"; // Display December????? Not sure why. Try the url if you want to see. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 I used selected_month, you are using selection_month $selection_month = $_GET["month"];$month = date('F', mktime(0,0,0,$selected_month,1)); Quote Link to comment Share on other sites More sharing options...
neobolt Posted May 1, 2013 Author Share Posted May 1, 2013 (edited) AHHHH, Thanks, something so small and simple.Much appreciated, everything works perfectly now. Edited May 1, 2013 by neobolt Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.