Manoj
Manoj

Reputation: 67

Subtract two dates to display number of Days

<?php
    $datetime1 = new DateTime("$da[tofollowon]");

    $datetime2 = new DateTime();

    $difference = $datetime1->diff($datetime2);

    $days = $difference->days;
?>

Above php code displays difference in two dates, but i want to subtract these two dates datetime2 from datetime1 which should even display negative values.

Upvotes: 0

Views: 33

Answers (2)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

try

$start = strtotime('2010-01-25');
$end = strtotime('2010-02-20');
$days_between = ceil(abs($end - $start) / 86400);

For more :- Finding the number of days between two dates

Upvotes: 1

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

Try this

 $d1 = strtotime("2014-01-10"); // or your date as well
 $d2 = strtotime("2014-01-01");
 $datediff = $d1 - $d2;
 echo floor($datediff/(60*60*24)).' days';

Upvotes: 1

Related Questions