Dear Friends,
I created Table in PHP. Columns are
SrNo. ---- Tender Detail----- Last Date----- Remaining Days ---------- Status(Pending/Proceded)
I have Database in mysql.
I get "last date" from database and minus with Current date. But i tried there is any problem please, check.
Code is below

<?php

function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
{
    $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);

    $interval = date_diff($datetime1, $datetime2);

    return $interval->format($differenceFormat);

}
include "headeradmin.php";
include "conn1.php";
//$sql=SELECT DATE_FORMAT(ldate,GET_FORMAT(DATE,'EUR') FROM tentb);
//$sql="SELECT DATEDIFF(CURDATE(),ldate) AS DiffDate"
$sql="SELECT id,edate,cdetail,tdetail,DATE(ldate) AS ldate FROM tentb ";
$result=$conn1->query($sql);
?> <div id="userdiv"> <ul> <li> User Name: 
        <li> Status: 
        <li> Logout: <a href="adminlogin.php">Click here</a> </ul> </div> <br> <div id="container"> <h2>Current Date: <?php echo date('Y-M-d') ?></h2> <div id="contant"> <div id="contantleft"> <table align= right> <th>Sr#  </th> <th>Client Detail </th> <th>Tender Description </th> <th>Last Date</th> <th>Remaining Days</th> <th>Status</th> <?php

               $i=1;
                while ($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td>".dateDifference('edate','ldate',$differenceFormat = '%d' )."</td>";
                echo"</tr>";
                $i++;
                }
                ?> </table> </div><!----Contantleft End ----->

i received
Fatal error: Call to a member function format() on a non-object in C:\wamp\www\SprintWeb\adminfrm.php on line 12
and
Warning: date_diff() expects parameter 1 to be DateTimeInterface, boolean given in C:\wamp\www\SprintWeb\adminfrm.php on line 10

Recommended Answers

All 7 Replies

function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
echo "<td>".dateDifference('edate','ldate',$differenceFormat = '%d' )."</td>";

Your function expects 2 dates as the first parameters. When you invoke the function, you are passing strings.

I think you meant:
echo "<td>".dateDifference($row['edate'],$row['ldate'],$differenceFormat = '%d' )."</td>";

Hello ryan,
yes, but I want to put Current date instead of

$row['edate']

..
how to put .?

I tried but there is error. please, check my code.

<input type="text"  name='cdate' value="<?php echo date('Y-m-d') ?>" /> 
<?php
        $cdate=$_POST['cdate'];
        $start=date('Y-m-d',$cdate);
         $i=1;
                while ($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td>".dateDifference($strat ,$row['ldate'],$differenceFormat = '%d' ) ."</td>";
                echo"</tr>";
                $i++;
                }
   ?>

Please, Help me

       $start=date('Y-m-d',$cdate);
       echo "<td>".dateDifference($strat ,$row['ldate'],$differenceFormat = '%d' ) ."</td>";
       You misspelled "start" as "strat"

Thx for indicating error...

I got it , But calculation is wrong please, check plz
Sr#---- C. Detail----Tender Des.----Last Date----Rem Days--Status

1----PAF ------Mics. Items----2016-10-17--15---Pending
2---POFs----Mics. Items----2016-10-20---18-Pending
NOTE-: It adds 12days in every remainig days

<?php

$cdate=$_POST['cdate'];
$start=date('Y-m-d',$cdate);
//$start=new DateTime("now");

function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
{
    $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);
    $interval = date_diff($datetime1, $datetime2);
    return $interval->format($differenceFormat);
}
include "headeradmin.php";
include "conn1.php";
//$sql=SELECT DATE_FORMAT(ldate,GET_FORMAT(DATE,'EUR') FROM tentb);
//$sql="SELECT DATEDIFF(CURDATE(),ldate) AS DiffDate"
$sql="SELECT id,edate,cdetail,tdetail,DATE(ldate) AS ldate FROM tentb ";
$result=$conn1->query($sql);

?>

    <form action="adminfrm" method="post"></form>

<div id="userdiv"> <ul> <li> User Name:</li>
        <li> Status:</li>
        <li> Logout: <a href="adminlogin.php">Click here</a> </li></ul>
        </div> <br> <div id="container">
        <h2>Current Date: <?php echo date('Y-M-d') ?></h2>
    <input type="text"  name='cdate' value="<?php echo date('Y-m-d') ?>" />

 <div id="contant">
     <div id="contantleft">

       <table align= right>
        <th>Sr#  </th>
        <th>Client Detail </th>
        <th>Tender Description </th>
        <th>Last Date</th>
        <th>Remaining Days</th>
        <th>Status</th>

        <?php
         $i=1;
                while ($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td>".dateDifference($start,$row['ldate'],$differenceFormat = '%d' ) ."</td>";

                echo"</tr>";
                $i++;
                }

Dear Friends,
I soved my problem
please, check code below

<!DOCTYPE html>
<?php

//$cdate=$_POST['cdate'];
$start=date('Y-m-d');
//$start=new DateTime("now");

function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
{
    $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);
    $interval = date_diff($datetime1, $datetime2);
    return $interval->format($differenceFormat);
}
include "headeradmin.php";
include "conn1.php";
//$sql=SELECT DATE_FORMAT(ldate,GET_FORMAT(DATE,'EUR') FROM tentb);
//$sql="SELECT DATEDIFF(CURDATE(),ldate) AS DiffDate"
$sql="SELECT id,edate,cdetail,tdetail,DATE(ldate) AS ldate FROM tentb ";
$result=$conn1->query($sql);

?>

    <form action="adminfrm" method="post"></form>

<div id="userdiv"> <ul> <li> User Name:</li>
        <li> Status:</li>
        <li> Logout: <a href="adminlogin.php">Click here</a> </li></ul>
        </div> <br> <div id="container">
        <h2>Current Date: <?php echo date('Y-M-d') ?></h2>

 <div id="contant">
     <div id="contantleft">

       <table align= right>
        <th>Sr#  </th>
        <th>Client Detail </th>
        <th>Tender Description </th>
        <th>Last Date</th>
        <th>Remaining Days</th>
        <th>Status</th>

        <?php
         $i=1;
                while ($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td>".dateDifference($start,$row['ldate'],$differenceFormat = '%d' )."</td>";
                echo "<td> Pending</td>";
                echo"</tr>";
                $i++;
                }
      ?>
      </table> </div>
      <!----Contantleft End ----->
      <?php include('sidebaradmin.php') ?>

   </div><!-----Contant End---->
</div><!-----Container End------>

<?php include('footer.php') ?>
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.