Reputation: 13
My date is in format day::month::year-h-m-s
now I want to take difference between these 2 dates only in days?
Upvotes: 0
Views: 2013
Reputation: 572
try this one
$fisrstDate = new DateTime(date('Y-m-d', strtotime($fisrstDate)));
$secondDate = new DateTime(date('Y-m-d', strtotime($secondDate)));
echo $fisrstDate->diff($secondDate)->days;
Upvotes: 0
Reputation: 771
Try this
$dateDiff=date_diff(date_create($date1),date_create($date2));
echo $dateDiff->format("%a days");
Upvotes: 1
Reputation: 339
PHP:
<?php
$otherday = date_create("01-05-2015");
$today= date_create(date("d-m-Y"));
$days = $today->diff($otherday);
echo $days->format("%R%a");
?>
%R means (+) or (-) you can use only %a.
Upvotes: 1
Reputation: 5322
you can do this way
$date1 = new DateTime(date('Y-m-d', strtotime("2013-08-07 13:00:00")));
$date2 = new DateTime(date('Y-m-d', strtotime("2013-08-08 12:00:00")));
echo $date1->diff($date2)->days;
Upvotes: 1