Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Explain mail function in PHP with syntax?

1050


What percentage of websites use php?

1038


What is htaccess in php?

1359


What would occur if a fatal error was thrown in your php program?

1124


Does cors prevent csrf?

1002


Explain the installation of PHP on UNIX systems?

1162


Can we use include ("xyz.php") two times in a php page "index.php"?

1066


What is the difference between abstract class and interface in php?

1216


What difference between require() and require_once()?

1146


What are the advantages of stored procedures?

1057


How to get number of elements in an array?

1050


What is needed to be able to use image function?

1083


Explain me is it possible to destroy a cookie?

994


How do we get the current session id?

1055


What is the purpose of a query?

978