Computing.Net > Forums > Web Development > php calculation of dates

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

php calculation of dates

Reply to Message Icon

Name: BASSUHG
Date: March 1, 2009 at 05:44:30 Pacific
OS: Windows XP
Subcategory: PHP
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Radix-64
Date: March 12, 2009 at 09:15:25 Pacific
Reply:

Hi, can you provide examples of the test dates that you have tried and the exact results?


0

Response Number 2
Name: BASSUHG
Date: March 13, 2009 at 06:53:17 Pacific
Reply:

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


0

Response Number 3
Name: Radix-64
Date: March 13, 2009 at 15:36:42 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Get number of words from ... bUILD POSTING ARTICLE. .



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: php calculation of dates

PHP Script Need help www.computing.net/answers/webdevel/php-script-need-help/2243.html

$PATH php error www.computing.net/answers/webdevel/path-php-error/294.html

PHP JPEG file download on Mac(IE) www.computing.net/answers/webdevel/php-jpeg-file-download-on-macie/1534.html