my date format is: Jan-21-2016 I want to check if it is in the past or not in PHP. How can I do it?
Asked
Active
Viewed 5,219 times
1 Answers
8
Using strtotime()
:
if(strtotime($date)<strtotime("today")){
echo "past";
} elseif(strtotime($date)==strtotime("today")){
echo "today";
} else {
echo "future";
}

Ben
- 8,894
- 7
- 44
- 80
-
It works. Thank you very much. – nilesh_ramteke Jan 21 '16 at 13:05
-
Isn't `time()` simpler than `strtotime("today")`? – TRiG Jun 07 '17 at 13:06
-
2@TRiG, `time()` would give the current date and **time**, but `strtotime('Jan-21-2016')` would give the date at midnight of that day. This will cause of issue for the `today` case. – bakavic Jun 09 '17 at 06:52