无法从出勤记录中检索日期

时间:2015-05-11 07:04:48

标签: php

我有考勤记录数据库

  

id | emp_id | attendance_date。

我已插入attendance_date by varchar(200)。如果我选​​择startdate,我想检索enddatedatetime picker之间的日期。我的日期格式为m/d/Y。 如果我检索04/1/2015 and 04/30/2015,则不会显示。但如果我检索 12/1/2014 and 12/31/2014,显示记录。问题是月份。月前有不必要的零。我怎么能这样做? 请帮帮我?数据库是这样的。 id emp_id attendance_date 1 1 10/4/2014 10:36 2 1 10/30/2014 9:36

attendanceRecord.php

    <form enctype="multipart/form-data" method="post" class="form-inline" role="form" action="attendance_search.php">    

    <!--Start Date-->  
         <div class="">
            <div class="form-group required">
                   <label for="startdate" class="control-label">Start Date:</label>                                
                  <input class="form-control"  placeholder="Choose Date " type="text" id="datepicker-8" name="startdate" required="required" />                    
               </div>
        </div><br/><br/>

        <!--End Date-->  
         <div class="">
            <div class="form-group required">
                   <label for="enddate" class="control-label">End Date:</label>                               
                  <input class="form-control"  placeholder="Choose Date " type="text" id="datepicker-9" name="enddate" required="required" />

               </div>              
        </div>
         <!--Create Button-->     
    <div class=""> <br/>         
        <input class="btn btn-success" type="submit" value="Search" />          
    </div>
   </form>  

**attendance_search.php**





<form method="post" name="salaryform" action="" class="form-vertical">         

               <div class="table table-hover">       
                <table border="1" cellspacing="0" class="table" >                 
                   <tr class="success" >                     
                      <th>Employee ID</th>                    
                      <th>Date</th>                   
                      <th>Timein Timeout</th>                                                             
                  </tr> 
                  <?php
                     include 'connect.php';
                     error_reporting(E_ALL ^ E_NOTICE);             
                                                                           if(!empty($_POST)){                  
                     $startdate= mysql_real_escape_string(date( "m/d/Y H:i:s",strtotime($_POST["startdate"])));
                     $enddate= mysql_real_escape_string(date("m/d/Y H:i:s",strtotime($_POST["enddate"])));                   


                    $sql="SELECT * FROM attendance2 WHERE attendance_date   between '".$startdate."' and '".$enddate."'";                   

                    $retval = mysql_query($sql);
                    if (!$retval) {
                        die('Could not get data: ' . mysql_error());
                    }
                    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
                        echo '<tr class="active">';
                        echo '<td >'.$row['emp_id'].'</td>';                                                      
                        echo '<td>'.$row['attendance_date'].'</td>';                
                        echo '<td>'.$row['timein_timeout'].'</td>';   

                    }


                    echo '</tr>';
                    echo '</table>';                                
                    }

                   ?>           
               </table>   

             </div>              
         </form>    

1 个答案:

答案 0 :(得分:0)

如果您不需要开始日期和结束日期的时间,那么您可以这样做,

$startdate = mysql_real_escape_string(date( "m/d/Y",strtotime($_POST["startdate"])));
$enddate = mysql_real_escape_string(date("m/d/Y",strtotime($_POST["enddate"])));                   


$sql="SELECT * FROM attendance2 WHERE date(attendance_date)   between '".$startdate."' and '".$enddate."'";