hi everyone,
i am retrieving some 25 dates from html table, and calculating.
suppose date is 03-feb-2009 i am converting it to 03-02-2009 and calculating with present date.

It gives the same answer to each and every date calculated,
any one helpme,
i have tried google n php.net,
its urgent
thanks a million in advance

<?php

function parse_array($string,$beg_tag,$close_tag)
    {
      preg_match_all("($beg_tag(.*)$close_tag)siU", $string, $matching_data);
      return $matching_data[0];
    }

$string=file_get_contents("callback.html");
$date1=parse_array($string,"<td nowrap=\"nowrap\">","</td>");

for($i=0;$i<count($date1);$i++)
{
echo $date1[$i]."</br>";
echo "</br>";
$date2=date("d-m-Y");
print "If we minus ".$date1[$i]." from ".$date2." we get ".dateDiff("-", $date2, $date1[$i]) . ".";
}


function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);


if($date_parts1[1]=="Jan")
{
$date_parts1[1]='01';

}


if($date_parts1[1]=="Feb")
{
$date_parts1[1]='02';
}


if($date_parts1[1]=="Mar")
{
$date_parts1[1]='03';

}


if($date_parts1[1]=="Apr")
{
$date_parts1[1]='04';
}


if($date_parts1[1]=="May")
{
$date_parts1[1]='05';

}


if($date_parts1[1]=="Jun")
{
$date_parts1[1]='06';
}


if($date_parts1[1]=="Jul")
{
$date_parts1[1]='07';

}


if($date_parts1[1]=="Aug")
{
$date_parts1[1]='08';
}


if($date_parts1[1]=="Sep")
{
$date_parts1[1]='09';
}


if($date_parts1[1]=="Oct")
{
$date_parts1[1]='10';
}

if($date_parts1[1]=="Nov")
{
$date_parts1[1]='11';

}


if($date_parts1[1]=="Dec")
{
$date_parts1[1]='12';
}


$date_parts1[2]='20'.$date_parts1[2];
//$start_date=gregoriantojd(02,03,2009);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[0], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[0], $date_parts2[2]);

echo $date_parts1[0]."/".$date_parts1[1]."/".$date_parts1[2]."<br>";
echo $date_parts2[0]."/".$date_parts2[1]."/".$date_parts2[2]."<br>";

return floor(($end_date - $start_date)/86400)."<br>";
}
?>

this is my code

Hi Basshug,

I'm not entirely sure what it is you're trying to achieve, however the php method strtotime is very useful and powerful.

Using the strtotime method, you could pass it your dates, and it'll return a unix timestamp for each. Then you'll simply be doing a calculation using two numbers.

If you then subtract your dates from one another as you already are, and divide the result by the number of seconds in a day, you'll have the number of days between the two dates.

R.

hi,
new step in my process

how do i send array items as parameters to the function

<?php

function parse_array($string,$beg_tag,$close_tag)
    {
      preg_match_all("($beg_tag(.*)$close_tag)siU", $string, $matching_data);
      return $matching_data[0];
    }

$string=file_get_contents("callback.html");
$date1=parse_array($string,"<td nowrap=\"nowrap\">","</td>");

for($i=0;$i<count($date1);$i++)
{
echo $date1[$i]."</br>";
echo "</br>";
$date2=date("d-m-Y");
print "If we minus ".$date1[$i]." from ".$date2." we get ".dateDiff("-", $date2, $date1[$i]) . ".";
}


function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);


$start_date=gregoriantojd($date_parts1[1], $date_parts1[0], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[0], $date_parts2[2]);

echo $date_parts1[0]."/".$date_parts1[1]."/".$date_parts1[2]."<br>";
echo $date_parts2[0]."/".$date_parts2[1]."/".$date_parts2[2]."<br>";

return floor(( $end_date - $start_date)/86400)."<br>";
}
?>

in html table 1st date is 01-feb-09,
2nd date is 02-jan-2009

this is the script output.

03-Feb-09


Warning: gregoriantojd() expects parameter 1 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\nw\new8.php on line 27
03/Feb/09
02/03/2009
If we minus 03-Feb-09 from 02-03-2009 we get 28
. 02-Jan-09


Warning: gregoriantojd() expects parameter 1 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\nw\new8.php on line 27
02/Jan/09
02/03/2009
If we minus 02-Jan-09 from 02-03-2009 we get 28
. 10-Feb-09


help me out,
thanx in advance

Sorry for replying late,
Thanks for taking out your time and helping :-)

This article has been dead for over six months. Start a new discussion instead.