prob w/datediff

1Tsme1941

Member
Hi guys, please advise me as to what I'm doing wrong. My test database table fields have
"payrec" has 'p', "amtdue" is blank, recur has 'N' and "duedate" is past.
---------------------------------
the code:

<html><head>
<style>
@page { size 8.5in 11in; margin: 2cm }
div.page { page-break-after: always }
</style>
</head><body><center>
<div class="page">

<?php
//Open a new connection to the MySQL server
require_once "getacctdb.php";

//MySqli Select Query
$results = $mysqli->query (SELECT acctno, recur, pd, payrec, bname, datepaid, amtdue,
DATEDIFF(CURDATE(),duedate) AS dayslate, FROM accttbl` WHERE payrec = 'p' AND amtdue != '' AND
recur = 'N'";

echo date('m/d/y');
?>
<font size=+1><b><center> Accounts Payable Report</font></center></b></b><br />
<table cellspacing=0 cellpadding=0 border=1>
<thead>
<tr>
<th bgcolor="#ccffff">acct#</th>
<th bgcolor="#ccffff">creditor</th>
<th bgcolor="#ccffff">due date</th>
<th bgcolor="#ccffff">days late</th>
<th bgcolor="#ccffff">amt due</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
$totdue += $row['amtdue'];
echo '
<tr>
<td>', $row['acctno'], '</td>
<td>', $row['bname'], '</td>
<td>', $row['duedate'], '</td>
<td>', $row['dayslate'], '</td>
<td align=right class="currency">$'.number_format($row['amtdue'],2).'</td>
</tr>';
}
echo '
<tr>
<th bgcolor="#ccffff" scope="row" colspan="7">Grand Total:</th>
<td bgcolor="#FFD4D4" class="currency">$'.number_format($totdue, 2, '.', ''), '</td>
</tr>
</table>';

echo "Page 1";
?>
</div>
<div class="page">
<?php
echo "Page 2";

mysql_close();
?>
</body></html>
---------------------------------
the result:
query ("SELECT acctno, recur, pd, payrec, bname, DATEDIFF(CURDATE(),duedate) AS dayslate, datepaid, amtdue FROM accttbl` WHERE payrec = 'p' AND amtdue != '' AND recur = 'N'"); echo date('m/d/y'); ?>
Accounts Payable Report

'; } echo '
acct# creditor due date days late amt due
', $row['acctno'], ' ', $row['bname'], ' ', $row['duedate'], ' ', $row['dayslate'], ' $'.number_format($row['amtdue'],2).'
Grand Total: $'.number_format($totdue, 2, '.', ''), '
'; echo "Page 1";
 

Trizoy

VIP Member
DATEDIFF has 3 params to pass. 'Interval', 'Date1', 'Date2'. Looks like you have Date1 and Date2, but not how you want the "Difference' returned in.

You probably want day. so try 'DATEDIFF(day, CURDATE(), duedate) AS dayslate'

Options:
  • year, yyyy, yy = Year
  • quarter, qq, q = Quarter
  • month, mm, m = month
  • dayofyear = Day of the year
  • day, dy, y = Day
  • week, ww, wk = Week
  • weekday, dw, w = Weekday
  • hour, hh = hour
  • minute, mi, n = Minute
  • second, ss, s = Second
  • millisecond, ms = Millisecond
 
Top