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?

Answers were Sorted based on User's Feedback



How can we know the number of days between two given dates using PHP?..

Answer / ash

$date1 = date('Y-m-d');
$date2 = "2007-07-05";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60
* 24);
echo " No of $days difference";

Is This Answer Correct ?    25 Yes 4 No

How can we know the number of days between two given dates using PHP?..

Answer / richa

Something we must know about strtotime

(try putting up a date grater than 30 years)

yes it will give an unexpected output, because it uses, unix
timestamp, and thus doesnt treat a date greater than 30 yrs,
as a correct value.

Amazing but true

Is This Answer Correct ?    6 Yes 0 No

How can we know the number of days between two given dates using PHP?..

Answer / savvy

"The function expects to be given a string containing a US
English date format and will try to parse that format into a
Unix timestamp (the number of seconds since January 1 1970
00:00:00 GMT), relative to the timestamp given in now, or
the current time if none is supplied." --- in php.net So Be
careful when calculating with strtotime(). Therefore in the
above ans it might be like this way
$date1 = date('M-d-Y');
$date2 = "August-07-2007";

Is This Answer Correct ?    6 Yes 2 No

How can we know the number of days between two given dates using PHP?..

Answer / dheeraj

<?php
$date1=date('Y-m-d');
$date2="2007-09-15";
echo (round($diff=strtotime($date1)-strtotime($date2)))/86400;
?>

Is This Answer Correct ?    5 Yes 1 No

How can we know the number of days between two given dates using PHP?..

Answer / rameshfromind

There is one function for gregoriantojd that means convert
to gregorian calendar date to julian date count.

Below the example for counting days between two date.

<?
$startDate = '01-01-2008' // mm-dd-yyyy/yy
$endDate = '01-30-2008' // mm-dd-yyyy/yy
echo gregoriantojd($endDate) - $gregoriantojd($startDate);
?

// OUTPUT

29

Is This Answer Correct ?    5 Yes 2 No

How can we know the number of days between two given dates using PHP?..

Answer / pushpendra thakur

the first 1 is correct answer

Is This Answer Correct ?    3 Yes 1 No

How can we know the number of days between two given dates using PHP?..

Answer / 44

44

Is This Answer Correct ?    3 Yes 1 No

How can we know the number of days between two given dates using PHP?..

Answer / 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

More PHP Interview Questions

What is the difference between implode() and explode() in php?

0 Answers  


What is the difference between $_files['userfile']['name'] and $_files['userfile']['tmp_name']?

0 Answers  


Do you know what are traits?

0 Answers  


What is properties of class?

0 Answers  


What is MVC structure in Magento?

4 Answers  


How can we submit a form without a submit buttom?

12 Answers   A1 Technology, IBM,


What are the basic steps to store PHP session in to Database?

1 Answers   Rediff,


What is magic quotes?

0 Answers  


Is php a cms?

0 Answers  


What are the options to transfer session ids?

0 Answers  


When should you use a stored procedure?

0 Answers  


What's the difference between accessing a class method via -> and via ::?

0 Answers  


Categories