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

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

530


What is var_dump function in php?

522


What is ci in php?

528


Is php a mvc?

500


Is empty in excel?

525






How to create a text file in PHP?

604


What is factory pattern in php?

483


How to swap two variables without using 3rd temp variable.

488


What is the use of mysql_real_escape_string in php?

443


How do you check if a variable has been set in php?

503


Explain some most commonly use string functions in php?

493


Which php framework is best for web development?

490


What is the apache?

518


Where are cookies stored php?

496


What is difference between python and php?

503