简体   繁体   中英

how to select record from database based on html date picker chosen value

i have this html date picker `

 <form action="" method="POST">
  <input type="date"     name="date">
 <input type="submit" style="position: relative; bottom:100px;" name="submitmm" value="submit">


</form>

` then i am getting the chosen date and i want to select records from my database based on dateTime column i have in my database

if(isset($_POST['submitmm'])) {
      $date = $_POST['date'];
$con = new PDO($d,$user,$pass,$option);
        $con->setAttribute(PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION);
   
       $sql = "select * From transactions  where t_date=$date ";
                 $projresult = $con->query($sql);
}

but dateTime is like YYYY-MM-DD hh:mm:ss and date picker is mm/dd/yy

i resloved my problem like this:

$myDateTime2 = DateTime::createFromFormat('Y-m-d', $date);
$newDateString2 = $myDateTime2->format('Y-m-d H:i:s');
 $sql = "select * From transactions  where  op_date >  '$newDateString2'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM