Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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]."
";
echo $date_parts2[0]."/".$date_parts2[1]."/".$date_parts2[2]."
";return floor(($end_date - $start_date)/86400)."
";
}
?>
this is my code

this is what i get for each and every date
03-Feb-09
Warning: gregoriantojd() expects parameter 2 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Assignment\test\new8.php on line 39
03022009
13032009
If we minus 03-Feb-09 from 13-03-2009 we get 2454904
. 02-Jan-09
Warning: gregoriantojd() expects parameter 2 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Assignment\test\new8.php on line 39
02012009
13032009
If we minus 02-Jan-09 from 13-03-2009 we get 2454904
. 10-Feb-09
Warning: gregoriantojd() expects parameter 2 to be long, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Assignment\test\new8.php on line 39
10022009
13032009
If we minus 10-Feb-09 from 13-03-2009 we get 2454904

Hi, a couple of things jump out when reviewing the test results. I would suggest that you try to determine why one of your date formats, namely the Date2 variable, seems to have the month and day positions switched because the output has 13-03-2009 which is a European date format versus an American date format of 03-13-2009. For example, did you hardcode this in some way? Did the variable definitions or print commands switch the month and day position? Is the table where you are accessing the 25 dates have matching date format fields to your Date definition variables or are the month and day positions reversed?
It is a challenge trying to debug your code without commented variable definitions (e.g. which variable is the present date versus the date from the table and etc.), the actual table values and date format that you are comparing against, and knowing the line of code corresponds to the code error message reference of line 39.

![]() |
Get number of words from ...
|
bUILD POSTING ARTICLE. .
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |