Last active
January 11, 2016 08:28
-
-
Save fajarlabs/4c69a0275162cdbbb3e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$hariIni = date("Y-m-d"); | |
$kadaluarsa = '2015-05-05'; // Dari Database | |
/* | |
// Contoh 1 | |
$hariIni = strtotime($hariIni); | |
$kadaluarsa = strtotime($kadaluarsa); | |
if ($kadaluarsa < $hariIni) { | |
echo 'Sudah kadaluarsa'; | |
} else { | |
echo 'Belum kadaluarsa'; | |
}*/ | |
/** | |
* Versi PHP 5 >= 5.2.0 | |
*/ | |
// Contoh 2 | |
$hariIni_dt = new DateTime($hariIni); | |
$kadaluarsa_dt = new DateTime($kadaluarsa); | |
if ($kadaluarsa_dt < $hariIni_dt) { | |
echo 'Sudah kadaluarsa'; | |
} else { | |
echo 'Belum kadaluarsa'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment