Title: html dropdown list for month
Tags: php;html;dropdown
Question: I would like to ask why the dropdown list for month is not according to what the code said?The dropdown list supppose to show from september to october.
The screenshot image of the dropdown list
<select class="selectpicker" id="selectmonth" onchange="myFunction()"&gt;
<option value="<?php echo date('m', strtotime('-1 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-1 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-2 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-2 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-3 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-3 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-4 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-4 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-5 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-5 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-6 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-6 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-7 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-7 month')) ?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-8 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-8 month'))?&gt;</option&gt;
<option value="<?php echo date('m', strtotime('-9 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-9 month')) ?&gt; </option&gt;
<option value="<?php echo date('m', strtotime('-10 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-10 month')) ?&gt; </option&gt;
<option value="<?php echo date('m', strtotime('-11 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-11 month')) ?&gt; </option&gt;
<option value="<?php echo date('m', strtotime('-12 month')) ?&gt;"&gt;<?php echo date('F', strtotime('-12 month')) ?&gt; </option&gt;
</select&gt;
Comment: The said link is down. Can you embed the screenshot into your question ?

Comment: Link works fine for me. May be you have network problems with cache.

Here is the accepted answer: its done
<select class="selectpicker" id="selectmonth" onchange="myFunction()"&gt;
<option value="<?php echo date("m",strtotime("-1 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-1 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-2 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-2 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-3 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-3 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-4 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-4 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-5 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-5 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-6 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-6 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-7 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-7 Months",strtotime(date('01-m-Y')))) ?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-8 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-8 Months",strtotime(date('01-m-Y'))))?&gt;</option&gt;
<option value="<?php echo date("m",strtotime("-9 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-9 Months",strtotime(date('01-m-Y')))) ?&gt; </option&gt;
<option value="<?php echo date("m",strtotime("-10 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-10 Months",strtotime(date('01-m-Y')))) ?&gt; </option&gt;
<option value="<?php echo date("m",strtotime("-11 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-11 Months",strtotime(date('01-m-Y')))) ?&gt; </option&gt;
<option value="<?php echo date("m",strtotime("-12 Months",strtotime(date('01-m-Y')))) ?&gt;"&gt;<?php echo date("F",strtotime("-12 Months",strtotime(date('01-m-Y')))); ?&gt; </option&gt;
</select&gt;

Here is another answer: I guess this is because month is equivalent to 30 days in general and today is 31 October. Technically 31-30 is 1st October, which indeed is October when you echo date('F', strtotime('-1 month')).
// while tested in http://sandbox.onlinephpfunctions.com/. Them seem to have Oct 31 as their system date
<?php echo date('F', strtotime('first day -1 month'));?&gt; //Outputs: October
<?php echo date('F', strtotime('first day -2 month'));?&gt; //Outputs: September
<?php echo date('F', strtotime('first day -3 month'));?&gt; //Outputs: August
Try this:
<select class="selectpicker" id="selectmonth" onchange="myFunction()"&gt;
<?php for($i=1;$i<13;$i++){ ?&gt;
<option value="<?php echo date('m', strtotime("first day -$i month")) ?&gt;"&gt;<?php echo date('F', strtotime("first day -$i month")) ?&gt;</option&gt;
<?php }?&gt;
</select&gt;
Update
As I browse through, I found following as working solution:
<select class="selectpicker" id="selectmonth" onchange="myFunction()"&gt;
<?php for($i=1;$i<13;$i++){
$d=new DateTime('now');
$d-&gt;modify("first day +1 day -$i month");
?&gt;
<option value="<?php echo $d-&gt;format('m') ?&gt;"&gt;<?php echo $d-&gt;format('F') ?&gt;</option&gt;
<?php }?&gt;
</select&gt;
Comment for this answer: today is the 30th of october
Comment for this answer: mine timezone says 31 October :D
Comment for this answer: prepending "first day " seems to solve the problem mysteriously.
Comment for this answer: It also depends on the time of the PHP server, not the user's machine.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:10/31/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><html><dropdown>', 'Title': 'html dropdown list for month', 'ViewCount': 1471, 'id': 40336228, 'user_AboutMe': '', 'user_AccountId': 9459788.0, 'user_DisplayName': 'hihi', 'user_Reputation': 47.0, 'user_Views': 15.0, 'user_id': 7033884.0}}