SUCCESSGANDE SUCCESSGANDE - 3 months ago 12
MySQL Question

php Calculate remain days of the year from order date

I have two tables orders and shares. order table has column called 'Order_Date', while share table has column called 'HoldingPeriod' so how can I determine the remaining days of customer order (Order_Date) from 365 days.
Please, Help I don't have any idea on how to initiate code on this but here is query from share table;

<?php
$SeeShare=ViewShares();
while($row=mysql_fetch_array($SeeShare))
{
$share = $row['ShareName'];
$numshares = $row['NumberShares'];
$askprice = $row['AskPrice'];
$bidprice = $row['BidPrice'];
$commfee = $row['CommFee'];
$ShareInterest=$row['CommPercent'];
$Maturity=$row['HoldingPeriod'];
}?>


Here is the code for querying Paid Orders

<?php

$status='';
$Paid=QueryPaidFor($status);
while($row=mysql_fetch_array($Paid))
{

$share=$row['ShareName'];
$sharenum=$row['NumberShares'];
$amount=$row['Order_Price'];
$status=$row['status'];
$orderdate=$row['OrderDate'];

}

?>

Answer

Use the following code snippet

$currentDate = date("Y-m-d");
$totalDays = $Maturity;
$usedDays = round(abs(strtotime($currentDate)-strtotime($orderdate))/86400);
$remainingDays = $totalDays-$usedDays;

Hope this helps you in solving the problem.