php calculation of dates

March 1, 2009 at 05:44:30
Specs: Windows XP
 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 urgentthanks a million in advance","");for(\$i=0;\$i";echo "
";\$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

See More: php calculation of dates

#1
March 12, 2009 at 09:15:25
 Hi, can you provide examples of the test dates that you have tried and the exact results?

Report •

#2
March 13, 2009 at 06:53:17
 this is what i get for each and every date03-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 3903022009 13032009If 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 3902012009 13032009If 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 3910022009 13032009If we minus 10-Feb-09 from 13-03-2009 we get 2454904

Report •

#3
March 13, 2009 at 15:36:42
 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.

Report •

Related Solutions