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
Does php have multiple inheritance?
What is action hooks and filter hooks?
How to update memcached when you make changes to php?
Tell us how to redirect a page in php?
What is the use of addslashes in php?
Does https prevent csrf?
Does php 7 support multiple inheritance?
Why use php artisan serve?
What is the tags in PHP is not a valid way to begin and end a PHP code block?
Do you have to initialize variables in php?
Can we set session value in javascript?
What is the difference between indexed and associative array?
How many types of arrays are there in php?
Why do we use session?
What are session variables in php?