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 / jitendra jhariya and sandeep s

function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1],
$date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1],
$date_parts2[2]);
return $end_date - $start_date;
}Now let us see how we use this function:$date1="07/11/2003";
$date2="09/04/2004";print "If we minus " . $date1 . " from "
. $date2 . " we get " . dateDiff("/", $date2, $date1) .
".";which generates If we minus 07/11/2003 from 09/04/2004
we get 421.

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of imagetypes() method?

539


Which cryptographic functions in php returns the longest hash value?

583


What is the timeout period on session values?

573


How to pass variables by references?

558


What is the importance of php?

528






What is the use of rand() in php?

610


What is the difference between unset and unlink?

540


What is the difference between get & post ?

543


Is python better than php?

509


What are the 5 types of variables?

572


What kind of things have you done on the social side?

8590


Can we extend final class in php?

512


What does the unset() function means?

593


What is the difference between php and core php?

494


What is curl php?

533