PHPBuilder - No: days Calculator

# No: days Calculator

by: John
|
April 4, 2002

Version: 0.1

Type: Function

Category: Calendars/Dates

Description: Calculate the no: of days between two given dates.

```function ddiff(\$fromdate,\$todate,\$days)
{
\$fromd = sscanf("\$fromdate","%d/%d/%d");
\$tod = sscanf("\$todate","%d/%d/%d");

\$yrdiff = \$tod[2]-\$fromd[2];
\$mondiff = \$tod[1]-\$fromd[1];
\$datediff = \$tod[0]-\$fromd[0];
\$datediff1 = 'fg';
if (\$yrdiff >= 0)
{
if (\$mondiff<0)
{
\$mondiff1 = \$mondiff + 12 - 1;
}
else if (\$mondiff>=0 and \$yrdiff>0)
{
\$mondiff1 = \$mondiff+12*\$yrdiff;
}
else
{
\$mondiff1 = \$mondiff;
}
\$days = 0;

if (\$mondiff1>1)
{
\$mon = \$fromd[1];
\$yr = \$fromd[2];

for(\$i=1 ; \$i<=\$mondiff1-1 ; \$i++ )
{
\$mon = \$mon+1;
if (\$mon>12)
{
\$mon=1;
\$yr =\$yr+1;
}
\$days =  \$days+date(t,mktime(0,0,0,\$mon,1,\$yr));
}
}
else if (\$mondiff1 == 1)
{
\$datediff1 = \$tod[0] + date(t,mktime(0,0,0,\$fromd[1],\$fromd[0],\$fromd[2])) - \$fromd[0];
}
else \$datediff1 = \$datediff;

\$days = \$days + \$datediff1 + 1;
return \$days;
}
\$days = ddiff("1/2/2002","15/3/2002",\$days);
echo "\$days <br>";```

Comment and Contribute

## Your comment has been submitted and is pending approval.

Author:
John

Comment:

Comment:

(Maximum characters: 1200). You have characters left.