i want to select some records between two certain date, how i can i do that? i have done the part for selecting the dates in html and some javascript.
<html>
<head>
<title>ivr.project [ View Number of Calls - Date Selection ]</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--//
function DateValidation()
{
var f_year, f_month, f_day, t_year, t_month, t_day, fleap, tleap;
f_year = document.form1.f_year.options[document.form1.f_year.selectedIndex].value;
f_month = document.form1.f_month.options[document.form1.f_month.selectedIndex].value;
f_day = document.form1.f_day.options[document.form1.f_day.selectedIndex].value;
t_year = document.form1.t_year.options[document.form1.t_year.selectedIndex].value;
t_month = document.form1.t_month.options[document.form1.t_month.selectedIndex].value;
t_day = document.form1.t_day.options[document.form1.t_day.selectedIndex].value;
fleap = f_year % 4;
tleap = t_year % 4;
if ((fleap > 0) && (f_month == 02) && (f_day > 28))
{
alert ('This is not a leap year!');
}
if ((tleap > 0) && (t_month == 02) && (t_day > 28))
{
alert ('This is not a leap year!');
}
if (((fleap == 0) && (f_month == 02) && (f_day > 29)) || ((f_month == 04) && (f_day > 30)) || ((f_month == 06) && (f_day > 30)) || ((f_month == 09) && (f_day > 30)) || ((f_month == 11) && (f_day > 30)))
{
alert('Please check the date again!');
}
if (((tleap == 0) && (t_month == 02) && (t_day > 29)) || ((t_month == 04) && (t_day > 30)) || ((t_month == 06) && (t_day > 30)) || ((t_month == 09) && (t_day > 30)) || ((t_month == 11) && (t_day > 30)))
{
alert('Please check the date again!');
}
}
function DateCheck()
{
var f_year, f_month, f_day, t_year, t_month, t_day, n, m, fleap, tleap;
f_year = document.form1.f_year.value;
f_month = document.form1.f_month.value;
f_day = document.form1.f_day.value;
t_year = document.form1.t_year.value;
t_month = document.form1.t_month.value;
t_day = document.form1.t_day.value;
n=document.form1.f_month.value.length;
m=document.form1.t_month.value.length;
fleap = f_year % 4;
tleap = t_year % 4;
if (f_year > t_year )//erro because of year
{
alert('Please check the year!');
return false;
}
if (((f_year >= t_year ) && (n > m)) || ((f_year >= t_year ) && (n == m) && (f_month > t_month)))//error because of month
{
alert('Please check the month!');
return false;
}
if ((f_year >= t_year) && (n == m) && (f_month >= t_month) && (f_day > t_day))//error because of day
{
alert('Please check the day!');
return false;
}
if (((fleap == 0) && (f_month == 02) && (f_day > 29)) || ((f_month == 04) && (f_day > 30)) || ((f_month == 06) && (f_day > 30)) || ((f_month == 9) && (f_day > 30)) || ((f_month == 11) && (f_day > 30)))
{
alert('Please check the date again!');
return false;
}
if (((tleap == 0) && (t_month == 02) && (t_day > 29)) || ((t_month == 04) && (t_day > 30)) || ((t_month == 06) && (t_day > 30)) || ((t_month == 09) && (t_day > 30)) || ((t_month == 11) && (t_day > 30)))
{
alert('Please check the date again!');
return false;
}
if ((fleap > 0) && (f_month == 02) && (f_day > 28))
{
alert ('This is not a leap year!');
return false;
}
if ((tleap > 0) && (t_month == 02) && (t_day > 28))
{
alert ('This is not a leap year!');
return false;
}
document.form1.action="trainee_bar.php";
document.form1.submit();
}
// -->
</script>
</head>
<body>
<table align="center">
<td align="center">
<form name="form1" method="post">
<p><b>Please select the date for viewing the data</b></p>
<p> <b> From:</b>Year
<select name = "f_year" OnChange="DateValidation()">
<? for ($i=2002; $i<2100; $i ) { ?>
<option value="<? echo $i ?>">
<? print $i ?>
</option>
<? }//************End of for loop***************
?>
</select>
Month
<select name = "f_month" OnChange="DateValidation()">
<option value="01">01</option><option value="02">02</option><option value="03">03</option>
<option value="04">04</option><option value="05">05</option><option value="06">06</option>
<option value="07">07</option><option value="08">08</option><option value="09">09</option>
<option value="10">10</option><option value="11">11</option><option value="12">12</option>
</select>
Day
<select name = "f_day" OnChange="DateValidation()">
<option value="01">01</option><option value="02">02</option><option value="03">03</option>
<option value="04">04</option><option value="05">05</option><option value="06">06</option>
<option value="07">07</option><option value="08">08</option><option value="09">09</option>
<option value="10">10</option><option value="11">11</option><option value="12">12</option>
<option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option>
<option value="19">19</option><option value="20">20</option><option value="21">21</option>
<option value="22">22</option><option value="23">23</option><option value="24">24</option>
<option value="25">25</option><option value="26">26</option><option value="27">27</option>
<option value="28">28</option><option value="29">29</option><option value="30">30</option>
<option value="31">31</option>
</select>
<b> To:</b>Year
<select name = "t_year" OnChange="DateValidation()">
<? for ($i=2002; $i<2100; $i ) { ?>
<option value="<? echo $i ?>">
<? print $i ?>
</option>
<? }//************End of for loop***************
?>
</select>
Month
<select name = "t_month" OnChange="DateValidation()">
<option value="01">01</option><option value="02">02</option><option value="03">03</option>
<option value="04">04</option><option value="05">05</option><option value="06">06</option>
<option value="07">07</option><option value="08">08</option><option value="09">09</option>
<option value="10">10</option><option value="11">11</option><option value="12">12</option>
</select>
Day
<select name = "t_day" OnChange="DateValidation()">
<option value="01">01</option><option value="02">02</option><option value="03">03</option>
<option value="04">04</option><option value="05">05</option><option value="06">06</option>
<option value="07">07</option><option value="08">08</option><option value="09">09</option>
<option value="10">10</option><option value="11">11</option><option value="12">12</option>
<option value="13">13</option><option value="14">14</option><option value="15">15</option>
<option value="16">16</option><option value="17">17</option><option value="18">18</option>
<option value="19">19</option><option value="20">20</option><option value="21">21</option>
<option value="22">22</option><option value="23">23</option><option value="24">24</option>
<option value="25">25</option><option value="26">26</option><option value="27">27</option>
<option value="28">28</option><option value="29">29</option><option value="30">30</option>
<option value="31">31</option>
</select></p>
<input type="button" name="butSubmit" value="Submit" onClick="return DateCheck();">
</td>
</table>
</body>
</html>
select records between a certain date
Moderator: General Moderators
$modyear = $f_year % 4; //checking for leap year
for ($y = $f_year; $y <= $t_year; $y ) {
for ($m = $f_month; $m <= $t_month; $m ) {
if ($m >= 13) {
$m = 1;
}
if ($m == $f_month && $y == $f_year) { //setting the starting day to do the couting
$start_day = $f_day;
}
if ($m == $t_month && $y == $t_year) { //setting the ending day to do the counting
$end_day = $t_day;
} elseif (($m == 1) || ($m == 3) || ($m == 5) || ($m == 7) || ($m ==
|| ($m == 10) || ($m == 12)) {
$end_day = 31;
} elseif (($m == 4) || ($m == 6) || ($m == 9) || ($m == 11)) {
$end_day = 30;
} elseif (($m == 2) && ($modyear > 0)) {
$end_day = 28;
} else {
$end_day = 29;
}
for ($d = $start_day; $d = $end_day; $d ) {
$date = "$d/$m/$y";
echo "$date\n";
}}}
the codes above is for me to select date from the starting date until the ending date, it is a little bit messy. but there is some errors in the code, i tried to use the echo function as above to show the result of the couting first, but the result is giving me same date repeatedly, like not ending.
can anyone tell me wat is wrong here??plzz....
for ($y = $f_year; $y <= $t_year; $y ) {
for ($m = $f_month; $m <= $t_month; $m ) {
if ($m >= 13) {
$m = 1;
}
if ($m == $f_month && $y == $f_year) { //setting the starting day to do the couting
$start_day = $f_day;
}
if ($m == $t_month && $y == $t_year) { //setting the ending day to do the counting
$end_day = $t_day;
} elseif (($m == 1) || ($m == 3) || ($m == 5) || ($m == 7) || ($m ==
$end_day = 31;
} elseif (($m == 4) || ($m == 6) || ($m == 9) || ($m == 11)) {
$end_day = 30;
} elseif (($m == 2) && ($modyear > 0)) {
$end_day = 28;
} else {
$end_day = 29;
}
for ($d = $start_day; $d = $end_day; $d ) {
$date = "$d/$m/$y";
echo "$date\n";
}}}
the codes above is for me to select date from the starting date until the ending date, it is a little bit messy. but there is some errors in the code, i tried to use the echo function as above to show the result of the couting first, but the result is giving me same date repeatedly, like not ending.
can anyone tell me wat is wrong here??plzz....