Date Difference In PHP – Find Date Difference
We can find out the difference between two given dates in PHP very easily. Consider the following PHP script:
<?php function dateDiff($dformat, $endDate, $beginDate) { $date_parts1=explode($dformat, $beginDate); $date_parts2=explode($dformat, $endDate); $start_date=gregoriantojd($date_parts1[1], $date_parts1[0], $date_parts1[2]); $end_date=gregoriantojd($date_parts2[1], $date_parts2[0], $date_parts2[2]); return $end_date - $start_date; } // adjust date parts according to date format 102 for d-m-y and 012 for m-d-y $date1="30-06-2008"; $date2="06-08-2008"; print "If we minus " . $date1 . " from " . $date2 . " we get " . dateDiff("-", $date2, $date1) . "."; ?>
Result will be
If we minus 30-06-2008 from 06-08-2008 we get 37
Tags: date, time, useful
Posted in: Checks, Date & Time, Useful Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0
Posted in: Checks, Date & Time, Useful Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Lyyza Says:
where can i put this coding at the html form..
i understand this coding but how can can implement this at html form
King Says:
@Lyyza: Actually, not for html form. You need to put it in some PHP file to work. Just put the code and modify date1 and date2 variables.
Lyyza Says:
can u give example where should i put that code in the php file.?
Jake Says:
@Lyyza
LOL