Comparing Dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cheryl
    New Member
    • Nov 2006
    • 9

    Comparing Dates

    I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.... What is the query of this..


    Please somebody help me....
  • CMNetworx
    New Member
    • Jan 2007
    • 4

    #2
    Here is one way, it requires that your dates are entered in by the unixtime function

    [php]
    $unixtime = strtotime('now' );

    mysql_select_db ("yay") or die(mysql_error ());
    $query = "SELECT * FROM tablename WHERE this = '$that' AND expires_on >= '$unixtime'"; [/php]

    expires_on is one of the column names so in yours it may be

    [php]AND listed >= '$unixtime'"[/php]

    Comment

    • CMNetworx
      New Member
      • Jan 2007
      • 4

      #3
      This wont let me edit since its past 5 min, so I will repost

      Here is one way, it requires that your dates are entered in by the unixtime function, which they may already be, and they may be translated out of..

      [php]
      $nice_post = date('F d Y', $this);
      //This will return the variable $this from unix time to a readable date

      $unixtime = strtotime('now' );
      //makes current time into unix time string

      //Can also be used like
      $time = strtotime("10 September 2000")

      mysql_select_db ("yay") or die(mysql_error ());
      $query = "SELECT * FROM tablename WHERE this = '$that' AND time >= '$unixtime'";

      //of course other variations would be = < or >[/php]

      expires_on is one of the column names so in yours it may be

      Comment

      • cassbiz
        New Member
        • Oct 2006
        • 202

        #4
        Hi Cheryl,

        I am working on a very similar project. Ronverdonk posted this earlier and here is a great query to check for date availability.

        [php]
        <?
        $query = "(SELECT * FROM table WHERE date BETWEEN '$var_from' AND '$var_to'
        OR date1 BETWEEN '$var_from' and '$var_to';)";
        ?>
        [/php]

        Comment

        • cassbiz
          New Member
          • Oct 2006
          • 202

          #5
          There is one more note that I found is that the arrival date must be plus 1 day when comparing to a room becoming available. Otherwise the room will say occupied when it is really available.

          Comment

          Working...