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?

Answer Posted / sachin

If we know the date format and separator used in dates,
we can separate them out into day, month and year.
e.g.

$d1 = '29-12-1985'; //dd-mm-yyyy
$d2 = '31-12-1985'; //dd-mm-yyyy

$d1_pieces = explode('-',$d1);
$d2_pieces = explode('-',$d2);

$timestamp_d1 =
mktime(0,0,0,$d1_pieces[1],$d1_pieces[0],$d1_pieces[2],);

$timestamp_d2 =
mktime(0,0,0,$d2_pieces[1],$d2_pieces[0],$d2_pieces[2],);

$diff = $d1-$d2;

$num_days = $diff/(24*60*60);

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many escape sequences are recognized in double-quoted strings?

953


What is the use of trim in php?

924


How to remove all duplicate values in array in php?

921


What is the difference between characters 34 and x34?

853


In PHP, fgets() is used to read a file one line at a time. State Whether True or False?

1134


How to make horizonatl menu and vertical menu responsive

2254


What does explode do in php?

968


What is mysql_fetch_array?

974


How to change the principal password?

965


Tell me how can we pass the variable through the navigation between the pages?

933


How do I find out the number of parameters passed into function9?

922


What are php filters?

914


What is composer used for?

897


What is session and Cokkies . How it works . tell some thing about Session_id()

1910


Which programming language does php resemble?

912