Hola,
Quiero calcular el número de días que hay entre dos fechas posteriores a 12/12/1582 y que se reciben por URL, del tipo "
loquesea.php?D1=1&M1=5&A1=2005&D2=10&M2=6&A2=2006".
Pero al ejecutar el código, como resultado me sale "0" y varios avisos del tipo "
Notice: Undefined variable: year in loquesea.php on line 129"
¿Alguna idea de qué hago mal? GRACIAS por adelantado.
Este es el código en el que estoy trabajando:
Código:
<?
function wrongData($day1, $month1, $year1, $day2, $month2, $year2)
{
$wrong=false;
if ($year2<$year1) {
$wrong=true;
} else {
if ($year2=$year1 && $month2<$month1) {
$wrong=true;
} else {
if ($year2=$year1 && $month2=$month1 && $day2<$day1) {
$wrong=true;
}
}
return($wrong);
}
}
function isLeapYear()
{
if ($year%400 == 0) {
$leap=true;
} else {
if ($year%100 == 0) {
$leap=false;
} else {
if ($year%4 == 0) {
$leap=true;
} else {
$leap=false;
}
}
}
return($leap);
}
function dayOfTheYear()
{
$dayscounter=$day;
if ($month >11) {
$daysCounter = $daysCounter + 30;
}
if ($month >10) {
$daysCounter = $daysCounter + 31;
}
if ($month >9) {
$daysCounter = $daysCounter + 30;
}
if ($month >8) {
$daysCounter = $daysCounter + 31;
}
if ($month >7) {
$daysCounter = $daysCounter + 31;
}
if ($month >6) {
$daysCounter = $daysCounter + 30;
}
if ($month >5) {
$daysCounter = $daysCounter + 31;
}
if ($month >4) {
$daysCounter = $daysCounter + 30;
}
if ($month >3) {
$daysCounter = $daysCounter + 31;
}
if ($month >2) {
$daysCounter = $daysCounter + 28;
}
if ($month >1) {
$daysCounter = $daysCounter + 31;
}
if (isLeapYear($year) && $month > 2) {
$daysCounter = $daysCounter + 1;
}
return($daysCounter);
}
function daysYearsAfter1583()
{
$daysCounter=0;
$currentYear=1583;
while ($currentYear<$year) {
$daysCounter=$daysCounter+365;
$leap=isLeapYear($currentYear);
if ($leap) {
$daysCounter=$daysCounter+1;
}
$currentYear=$currentYear+1;
}
return($daysCounter);
}
function daysAfter1583()
{
return(daysYearsAfter1583($year) + dayOfTheYear($year,$month,$day));
}
/****************** MAIN PROGRAM ********************/
$day1=$_GET["D1"];
$month1=$_GET["M1"];
$year1=$_GET["A1"];
$day2=$_GET["D2"];
$month2=$_GET["M2"];
$year2=$_GET["A2"];
if (wrongdata($day1, $month1, $year1, $day2, $month2, $year2)) {
print("E");
} else {
$counter1=daysAfter1583($year1, $month1, $day1);
$counter2=daysAfter1583($year2, $month2, $day2);
print($counter2-$counter1);
}
$day=date("d");
$month=date("m");
$year=date("Y");
?>