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
How to set session.gc_divisor properly?
How many types of errors in php?
How to remove the new line character from the end of a text line?
How many types of session are there?
Which character is used to match exactly one character?
Explain me what is x+ mode in fopen() used for?
What are magic constants in php?
Write a php function to convert all null values to blank?
How do I run a php file?
What are different types of Print Functions available in PHP?
Explain how to run the interactive php shell from the command line interface?
What is the difference between print() and echo() in PHP?
Where is session id stored?
Do you have to initialize variables in php?
Tell me what sized websites have you worked on in the past?