Loading ...
Sorry, an error occurred while loading the content.

Re: [phpXperts] Need help with Date comparison

Expand Messages
  • mizanur rahman
    hi mysql date saves as Y-m-d format, so if your inputted date is not in that format, its better to change it for comparison. $tmpdate =
    Message 1 of 1 , Sep 21, 2006
    • 0 Attachment
      hi
       
      mysql date saves as Y-m-d format, so if your inputted date is not in that format, its better to change it for comparison.
       
      $tmpdate = strtotime($_POST['startdate' ]);
       
      $startdate = date("Y-m-d", $tmpdate);
       
      // then you can run your query here
       
      $result = mysql_query( "SELECT * FROM $table where jobnumber
      = '$jobnumber' AND startdate = '$startdate' ");

      $num = mysql_result( $result,0) ;
       
      $validTime = false;
       
      if($num)
       {
      /*
      since you are looking for 3 days before the date in the database then it will be better to compare todays date with 3 days added.
      */
       
      $today = Date("Y-m-d");
       
      $tmpDate = strtotime($today) + 3*24*60*60;  // adding 3 days to todays date
       
      $convertedDate = date("Y-m-d", $tmpDate);
       
       
      $result = mysql_query( "SELECT * FROM $table where jobnumber
      = '$jobnumber' AND startdate <= '$convertedDate' ");
      $num1 = mysql_result( $result,0) ;
       
      if($num1)
       {
      echo "<h1> Welcome Technician</ h1>";
      include 'hupd.php';
       }
      else
       {
      echo "<h3>Enter Job Number and Start Date</h3>

      <form action = '$_SERVER[PHP_ SELF]' method ='post'>
      JobNumber:&nbsp& nbsp&nbsp< input type = 'text' name='jobnumber' ><br>
      StartDate:&nbsp& nbsp&nbsp& nbsp&nbsp& nbsp<input type = 'text'
      name='startdate' ><br><br>
      <input type = 'submit' value= 'submit'>
      </form>";
       }
       
      }
      else
      {
      echo "<h3>Enter Job Number and Start Date</h3>

      <form action = '$_SERVER[PHP_ SELF]' method ='post'>
      JobNumber:&nbsp& nbsp&nbsp< input type = 'text' name='jobnumber' ><br>
      StartDate:&nbsp& nbsp&nbsp& nbsp&nbsp& nbsp<input type = 'text'
      name='startdate' ><br><br>
      <input type = 'submit' value= 'submit'>
      </form>";
      }
       
       
       
      i hope this will help you
       
      thanks
      Mizan

       
      ----- Original Message ----
      From: alcarterguitars <alcarterguitars@...>
      To: phpexperts@yahoogroups.com
      Sent: Wednesday, September 20, 2006 10:26:57 PM
      Subject: [phpXperts] Need help with Date comparison

      I am new to php and am looking for some help with a date comparison.
      I have inserted the code below. I have a form and want the user to
      input a JobNumber and a date for submittal. I then want to compare
      that date and job number to the data in the MySQL database. If both
      match I then want another check run to compare dates. I want to only
      give access to the hupd.php file 3 days before the date in the
      database (This is very important and can't quite figure out how to do
      it). Thanks very much and let me know if you need more information.

      <?php

      $jobnumber = $_POST['jobnumber' ];
      $startdate = $_POST['startdate' ];
      $todays_date = date("Y-m-d" );

      include 'db.inc';

      // Connect to the MySQl database Server
      mysql_connect( $hostName, $username, $password) ;

      // Select a MySQL database
      mysql_select_ db($databaseName ) or die ("Unable to select the
      database");

      // Build Query
      $result = mysql_query( "SELECT * FROM $table where jobnumber
      = '$jobnumber' AND startdate = '$startdate' ");

      $num = mysql_result( $result,0) ;

      if (!$num) {
      echo "<h3>Enter Job Number and Start Date</h3>

      <form action = '$_SERVER[PHP_ SELF]' method ='post'>
      JobNumber:&nbsp& nbsp&nbsp< input type = 'text' name='jobnumber' ><br>
      StartDate:&nbsp& nbsp&nbsp& nbsp&nbsp& nbsp<input type = 'text'
      name='startdate' ><br><br>
      <input type = 'submit' value= 'submit'>
      </form>";

      } else {
      echo "<h1> Welcome Technician</ h1>";
      include 'hupd.php';
      }
      ?>



    Your message has been successfully submitted and would be delivered to recipients shortly.