I'm trying to determine number of days difference between the due duedate and current date and really need help.

<?php 
mysql_connect("localhost", "root", "");  
mysql_select_db(numbersdb) or die("Unable to select database");   
$query = "SELECT taxrate FROM numbdata" ;  
$result = mysql_fetch_assoc(mysql_query($query));   
$taxrate = $result['taxrate'];  
mysql_connect("localhost", "root", ""); 
mysql_select_db(oodb) or die("Unable to select database"); 

$query = "SELECT id, shipamt, duedate, charges, dayslate, tax, amtdue FROM oocust  WHERE 
DATEDIFF(NOW(), duedate) > 30 AND pd = '  '"; 
  
$result=mysql_query($query);
$num=mysql_numrows($result);
while($row = mysql_fetch_array($result))
   {
         $id = $row['id']; 
$shipamt = $row['shipamt'];   
$duedate = $row['duedate'];
$charges = $row['charges'];
$dayslate = $row['dayslate'];
        $tax = $row['tax']; 
 $amtdue = $row['amtdue'];      
$tax = $charges * $taxrate;     
 $amtdue = $charges + $tax + $shipamt; 

// $dayslate = ;

$sql = "UPDATE oocust SET tax = '" . mysql_real_escape_string($tax) . "', amtdue = '" . 

mysql_real_escape_string($amtdue) . "',dayslate = '" . mysql_real_escape_string($dayslate) . "' WHERE 

id='".$id."'";$sql = "UPDATE oocust SET
 tax = '" . mysql_real_escape_string($tax) . "',
 amtdue = '" . mysql_real_escape_string($amtdue) . "',
dayslate = '" . mysql_real_escape_string($dayslate) . "'
 WHERE id='".$id."'";
 mysql_query($sql) or die("Update query failed.");
 }
echo "Invoice Prep completed";
?>

Here is a code for date difference you can use $days and save it in your database.

<?
	$duedate = '2011-04-29';
	$currdate = date('Y-m-d');
	
	$date1 = $duedate;
	$date2 = $currdate;
	
	$diff = abs(strtotime($date2) - strtotime($date1));
	
	$years = floor($diff / (365*60*60*24));
	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
	
	echo "Difference is $years years, $months months, $days days.";
?>

Here is a code for date difference you can use $days and save it in your database.

<?
	$duedate = '2011-04-29';
	$currdate = date('Y-m-d');
	
	$date1 = $duedate;
	$date2 = $currdate;
	
	$diff = abs(strtotime($date2) - strtotime($date1));
	
	$years = floor($diff / (365*60*60*24));
	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
	
	echo "Difference is $years years, $months months, $days days.";
?>

thanks so much. I've been trying to get this for forever. Below is my new code. right now the only problem left is to figure out how to change $days to include number of days in $months as I just want to have days (1-90 or more).

<?php 
mysql_connect("localhost", "root", "");  
mysql_select_db(numbersdb) or die("Unable to select database");   
$query = "SELECT taxrate FROM numbdata" ;  
$result = mysql_fetch_assoc(mysql_query($query));   
$taxrate = $result['taxrate'];  
mysql_connect("localhost", "root", ""); 
mysql_select_db(oodb) or die("Unable to select database"); 
$query = "SELECT id, shipamt, duedate, charges, dayslate, tax, amtdue FROM oocust  WHERE DATEDIFF(NOW(), duedate) > 30 AND pd = '  '";   
$result=mysql_query($query);
$num=mysql_numrows($result);
while($row = mysql_fetch_array($result))
   {
         $id = $row['id']; 
$shipamt = $row['shipamt'];   
$duedate = $row['duedate'];
$charges = $row['charges'];
$dayslate = $row['dayslate'];
        $tax = $row['tax']; 
 $amtdue = $row['amtdue'];      
$tax = $charges * $taxrate;     
 $amtdue = $charges + $tax + $shipamt; 

	$currdate = date('Y-m-d');
	$date1 = $duedate;
	$date2 = $currdate;
	$diff = abs(strtotime($date2) - strtotime($date1));
	$years = floor($diff / (365*60*60*24));
	$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
	$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
	echo "Difference is $months months, $days days.";

$dayslate = $days;

$sql = "UPDATE oocust SET tax = '" . mysql_real_escape_string($tax) . "', amtdue = '" . mysql_real_escape_string($amtdue) . "',dayslate = '" . mysql_real_escape_string($dayslate) . "' WHERE id='".$id."'";$sql = "UPDATE oocust SET
 tax = '" . mysql_real_escape_string($tax) . "',
 amtdue = '" . mysql_real_escape_string($amtdue) . "',
dayslate = '" . mysql_real_escape_string($dayslate) . "'
 WHERE id='".$id."'";
 mysql_query($sql) or die("Update query failed.");
 }
echo "Invoice Prep completed";
?>

thanks a bunch for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.