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
Explain mail function in PHP with syntax?
What percentage of websites use php?
What is htaccess in php?
What would occur if a fatal error was thrown in your php program?
Does cors prevent csrf?
Explain the installation of PHP on UNIX systems?
Can we use include ("xyz.php") two times in a php page "index.php"?
What is the difference between abstract class and interface in php?
What difference between require() and require_once()?
What are the advantages of stored procedures?
How to get number of elements in an array?
What is needed to be able to use image function?
Explain me is it possible to destroy a cookie?
How do we get the current session id?
What is the purpose of a query?