How to get the name of the months between two dates in php

i want the list of months between two dates den i want to store that in the database.

input type=date name=date1
input type=date name=date2 onblurr=showmonth(date1,date2, month)
input type=text name=month value=‘’ id=month

then submit

*js function

showmonth(var1, var2, var3)
{
 var month = new Array();
    month[0] = "January";
    month[1] = "February";
    month[2] = "March";
    month[3] = "April";
    month[4] = "May";
    month[5] = "June";
    month[6] = "July";
    month[7] = "August";
    month[8] = "September";
    month[9] = "October";
    month[10] = "November";
    month[11] = "December";
 var n = month[var1.getMonth()];
    document.getElementById("month").innerHTML = n;
}
****************end ****************
then want to send the thing into the database
if(isset($_POST['submit']))
{
$date1=$_POST[date1 ];
$date2=$_POST[date2 ];
$month=$_POST[month];

foreach($month as $b)
{
$month=$month.'$b;';

}
den insert query
}

at least you can take date1 to generate a DateTime object and ->modify('+1 month') it until you reach date2 and grab the months in between.

How many months might there be, between the two dates? Could it be any number, fewer than twelve, is there a definition? Also, I think from your brief PHP you are planning on storing the months as a single comma-separated string in a database column, which may well be inefficient - what do you want to do with that list of months once it is in the table?

yes… once its in the data base i need to echo that thing into another page. help to sought out the code.
and max 2 months will be dere… and i need the names of that…

As @chorn said then, take the first date, keep adding a month to it and extracting the month from that, until you reach the second date.

help me by giving a rough idea of code

You have a stab at the code based on @chorn’s post above, and then post it here if you get stuck on something.

okay sure… :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.