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
Why does php need server?
Why we use get in php?
Why do we use php?
What is strlen php?
What are the correct and the most two common way to start and finish a PHP block of code?
Tell me what does the array operator '===' means?
What is the use of the function 'imagetypes()'?
What is config file in php?
In how many ways we can retrieve the data in the result set of mysql using php?
Explain NULL?
What are the new features available in php 7?
What are the steps for the payment gateway processing?
Is php better than python?
What is a php namespace?
Do you know how to get the ip address of the client?