Rishabh Sharma
Rishabh Sharma

Reputation: 13

PHP date difference calculate onlys for days

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

Answers (4)

D Coder
D Coder

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

Sunil kumar
Sunil kumar

Reputation: 771

Try this

$dateDiff=date_diff(date_create($date1),date_create($date2)); 
echo $dateDiff->format("%a days");

Upvotes: 1

Aruna Warnasooriya
Aruna Warnasooriya

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

Devsi Odedra
Devsi Odedra

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

Related Questions