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
How do I check if a given variable is empty?
Which method removes the last element from the end of an array?
When to use single quotes, double quotes, and backticks?
i m a B.E,passed out few yrs bak failed to find good job due to less marks now thinkin of a career as PHP developer. is it a lucarative field and wat r career prospects; hv heard dat initial salary is very less bout 6k also most jobs r contrct jobs.pls guide me need ur valuable advice.pls hellppp!! thnx..
Is salary fixed or variable cost?
Who is the father of php and what is the current version of php and mysql?
Can you use both this () and super () in a constructor?
What is a comment in php?
Which programming language does php resemble to?
What is abstraction php?
What are some new features introduced in php7?
What is meant by pdo in php?
What is difference between mysqli and mysql?
What is query string php?
What is traits? How it is used in php?