How can we know the number of days between two given dates
using PHP?
How can we know the number of days between two given dates
using MySQL?

Answer Posted / vinay sachan

<?PHP
// different between two dates by date_diff() function:-
$datetime1 = date_create('2010-01-01');
$datetime2 = date_create('2012-1-15');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%a days')."<br>";
//+744 days
echo $interval->format('%y-%m-%d days')."<br>";
//2-0-14 days
// different between two dates by strtotime() function:-
$now = time(); // or your date as well
$your_date = strtotime("2010-01-01");
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24)) ."<br>";
//744
?>

for more PHP questions and their best answers and PHP notes at http://onlinephpstudy.blogspot.com/

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does php have multiple inheritance?

515


What is action hooks and filter hooks?

498


How to update memcached when you make changes to php?

544


Tell us how to redirect a page in php?

541


What is the use of addslashes in php?

528






Does https prevent csrf?

520


Does php 7 support multiple inheritance?

516


Why use php artisan serve?

503


What is the tags in PHP is not a valid way to begin and end a PHP code block?

795


Do you have to initialize variables in php?

492


Can we set session value in javascript?

527


What is the difference between indexed and associative array?

507


How many types of arrays are there in php?

538


Why do we use session?

540


What are session variables in php?

525