Jump to content

Simple Date Question


neobolt

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'; }
  On 5/1/2013 at 2:11 PM, Barand said:

 

::)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.