Jump to content

Recommended Posts

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=04

My 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?

Thanks
John

Link to comment
https://forums.phpfreaks.com/topic/277492-simple-date-question/
Share on other sites

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'; }

 

::)

$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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.