php date less than another date
Asked Answered
D

1

10

given this kind of date object date("m/d/Y", strtotime($numerical." ".$day." of ".date("F")))

where it may give a mm/dd/yyyy day that is the "first Monday of August", for instance

how can I decide if this date is greater than, less than, or equal to today's date?

I need a now() method that works in this format and can be compared between date objects

I haven't tried date() < date() , yet. But I don't think that will work

any insight appreciated

Dortch answered 26/6, 2013 at 19:55 Comment(2)
You don't think it will work? Why not try it?Allophane
@DanyCaissy he wants to compare date()'s output, not the integer timestamp…Tennietenniel
T
19

Compare the timestamps:

if (strtotime($numerical." ".$day." of ".date("F")) < time()) {
    // older
} else {
    // newer
}

This is possible as strtotime() returns the seconds since 1.1.1970 and time() too. And in PHP you can easily compare integers...

Tennietenniel answered 26/6, 2013 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.