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
What is T_PAAMAYIM_NEKUDOTAYIM?
Explain how to execute a php script using command line.
How to get the number of characters in a string?
Which function is used in php to check the data type of any variable?
What is the difference between pop3 IMAP and MAPI?
How to write comment in php?
What is the basic function to search files for lines (or other units of text) that contain a pattern.
How to get ip address of a server in php?
Explain what are some new features introduced in php7?
What is curl php?
What is the use of strpos in php?
How to include a file code in different files in php?
What is oops php?
How to create connection in php?
How should a model be structured in mvc?