generate month
Moderator: General Moderators
generate month
Hi,
I want to created an drop down list that containing values like Jan, Feb, etc.
The drop down list should contains values for maximum 6 months.User able to select it.
For this the values have to be dynamically generated depending on the current month.
please help!
Thank you
I want to created an drop down list that containing values like Jan, Feb, etc.
The drop down list should contains values for maximum 6 months.User able to select it.
For this the values have to be dynamically generated depending on the current month.
please help!
Thank you
Last edited by bjen on Fri May 18, 2007 6:01 am, edited 1 time in total.
Code: Select all
$currentMonth = date("m");
$currentYear = date("Y");
for ($x=0;$x<6;$x++) {
echo date("M",mktime(0,0,0,$currentMonth+$x,1,$currentYear));
}
Sorry onion2k, actually i not want to get the next current month value.....
Below is the correct question:
I want to created an drop down list that containing values like Jan, Feb, etc.
The drop down list should contains values for maximum 6 months.User able to select it.
For this the values have to be dynamically generated depending on the current month.
Please help up...
Thank you.
Below is the correct question:
I want to created an drop down list that containing values like Jan, Feb, etc.
The drop down list should contains values for maximum 6 months.User able to select it.
For this the values have to be dynamically generated depending on the current month.
Please help up...
Thank you.
http://www.timvw.be/generate-a-menu-with-month-names/...
This technique gives you the twelve month names (localizable).. All you need to do is figure out the current month index, and get the 6 following (simple while loop incrementing $index, and getting the element at position $index % 12)
This technique gives you the twelve month names (localizable).. All you need to do is figure out the current month index, and get the 6 following (simple while loop incrementing $index, and getting the element at position $index % 12)
If the months don't change...
If they do change, or if they're controlled via an admin page or something, then I'd store them in a database table.
Code: Select all
$currentMonth = date("m");
$currentYear = date("Y");
switch ($currentMonth) {
case 1: $months = array(1,2,3,4,5,6); break;
case 2: $months = array(2,3,4,5,6,7); break;
case 3: $months = array(3,4,5,6,11,12); break;
//and all the other months...
}
foreach ($months as $m) {
echo date("M", mktime(0,0,0,$m,1,$currentYear));
}
feyd | Please use
Please Help!
Thank you
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi onion2k,
The year is not change once case 10, case 11 and case 12 is executed.
Output Script: Oct - 2007
Nov – 2007
Dec – 2007
Jan – 2007
Feb – 2007
Mar – 2007
It supposes to be like below output:
[color=red]Oct - 2007
Nov – 2007
Dec – 2007
Jan – 2008
Feb – 2008
Mar – 2008[/color]
Below is my script:Code: Select all
switch ($month)
{
case 1: $months = array(1,2,3,4,5,6); break;
case 2: $months = array(2,3,4,5,6,7); break;
case 3: $months = array(3,4,5,6,7,8 ); break;
case 4: $months = array(4,5,6,7,8,9); break;
case 5: $months = array(5,6,7,8,9,10); break;
case 6: $months = array(6,7,8,9,10,11); break;
case 7: $months = array(7,8,9,10,11,12); break;
case 8: $months = array(8,9,10,11,12,1); break;
case 9: $months = array(9,10,11,12,1,2); break;
case 10: $months = array(10,11,12,1,2,3); break;
case 11: $months = array(11,12,1,2,3,4); break;
case 12: $months = array(12,1,2,3,4,5); break;
}
foreach ($months as $m) {
echo date("M - Y", mktime(0,0,0,$m,1,$currentYear));
}Thank you
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
strtotime() is your friend.