Showing posts with label number of days. Show all posts
Showing posts with label number of days. Show all posts

Sunday, May 26, 2013

Find number of days between given two days in PHP

We are going to study how can we calculate the number of days between given two days. For the example I am going to find the number of days between current date and another given date.

<?php

    $year="1990";
    $month="March";
    $day="23";


$today=date('Y-m-d'); // in-built function to get current date.

$datetime1 = date_create($year.'-'.$month.'-'.$day); //Given date
$datetime2 = date_create($today); //System date for current date
$interval = date_diff($datetime1, $datetime2); //$datetime2 - $datetime1
$date_amount= $interval->format('%R%a');

echo($date_amount);

?>