php - Check if something is between two values?
How do I go about checking to see if the current date is between two other dates?
I've been trying different operators, but haven't been able to figure this out.
So, if I have afrom
date of2/2/2010
and ato
date of2/10/2010
, how can I returnTRUE
if the current date (2/4/2010
) falls between those two dates?
Answer
Solution:
Off the top of my head, I don't know of a date comparison operator in PHP, but I would use
strtotime()
on all three dates, then do simple mathematical comparisons.returns true.
Answer
Solution:
To do a comparison like this you need to do separate comparisons. If $d is the date you want to compare, $d1 is the earlier date, and $d2 is the later date, it would be something like:
Answer
Solution:
If past date one and before date two, then it's between them.
Answer
Solution:
the googles told me
http://answers.yahoo.com/question/index?qid=20081003113922AAHnQsp
Answer
Solution:
wouldn't this work ?