How to compare dates (i.e. 12/12/2005 with 11/12/2005)

Discussion in 'PHP' started by lost, Oct 27, 2005.

  1. #1
    I have 2 fields that take in date fields (MM/DD/YYYY) and I need to make sure that the second date input is correct in that it comes after the first date.
    For example:

    12/12/2005
    11/12/2005
    this would result in a fail, because the second date (11/12/2005) comes before the first date (12/12/2005).
     
    lost, Oct 27, 2005 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change the date to a timestamp and then compare (they are just ints).
    
    if (mktime (0,0,0,12,12,2005) <= mktime (0,0,0,11,12,2005)) {
          // fail
    } else {
          // dates are good
    }
    PHP:
     
    exam, Oct 27, 2005 IP
  3. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you!
     
    lost, Oct 27, 2005 IP
    exam likes this.
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're welcome!
     
    exam, Oct 27, 2005 IP