How to use PHP & Compare Date Time This function will be using PHP and using function Date Compare , Time Compare
ShotDev Focus:
- PHP & Compare Date/Time
Example
php_compare_date.php
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?php
function CompareDate($date1,$date2) {
$arrDate1 = explode("-",$date1);
$arrDate2 = explode("-",$date2);
$timStmp1 = mktime(0,0,0,$arrDate1[1],$arrDate1[2],$arrDate1[0]);
$timStmp2 = mktime(0,0,0,$arrDate2[1],$arrDate2[2],$arrDate2[0]);
if ($timStmp1 == $timStmp2) {
echo "\$date = \$date2";
} else if ($timStmp1 > $timStmp2) {
echo "\$date > \$date2";
} else if ($timStmp1 < $timStmp2) {
echo "\$date < \$date2";
}
}
echo CompareDate("2010-01-06","2010-05-06");
?>
</body>
</html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_compare_date.php
Screenshot


