#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    Date comparison. Valid if today or in future


    I know strtotime is the seconds from 1970-1-1 (or something like that).

    I wanna accept if date is today or in future. Is this correct?

    Thanks

    PHP Code:
    $exp_date $data[0]['checkin_date'];  //Format 2013-12-21
                    
    $todays_date date("Y-m-d"); 
                    
    $today strtotime($todays_date); 
                    
    $expiration_date strtotime($exp_date); 
                    if (
    $expiration_date >= $today)
                        {
                            
    $status "valid";
                        }
                    else
                        {
                            
    $status "expired"
                        } 
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,874
    Rep Power
    6351
    time() returns today's date as a timestamp. Don't do two operations when you can do one.

    And if the date you're comparing to comes from the database: WHERE whatever > NOW()
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by ManiacDan
    time() returns today's date as a timestamp. Don't do two operations when you can do one.

    And if the date you're comparing to comes from the database: WHERE whatever > NOW()
    Dates stored in my database have DATE format like '2014-12-12'. There is no hour, minute or seconds stored there. You know what I mean?
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,874
    Rep Power
    6351
    if they're honestly in DATE format then there's probably a 00:00:00 implied for Hours:Minutes:Seconds.

    Regardless, my advice still applies. Don't do two operations when you could do one at the beginning of this block of code. The rest appears to be correct.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo