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

Explain Creating and Naming an Array?

567


Is null function in php?

549


What is string function sql?

508


Why do you need php?

507


Tell me what are the correct and the most two common way to start and finish a php block of code?

508






What is list in PHP?

616


What is the difference between html and php?

525


Tell me what are the different types of errors in php?

488


How to create a session? How to remove data from a session?

500


How to remove all duplicate values in array in php?

499


Which method removes the last element from the end of an array?

472


Explain what does the unlink() function means?

529


Write a program in php to check whether a number is prime or not?

476


Does php have a future?

495


What are the features of php 7?

486