简体   繁体   中英

How to fetch data from table as per user input date with formatting using MySQL and PHP

I need one solution. I need to fetch data from table as per date using PHP and MySQL but here the user input is string type. I am explaining my table below.

id        name             date

 1         aaa         2017-10-23 16:56:34

 2         bbb         2017-10-23 16:56:34

 3         ccc         2017-10-12 13:56:34

 4         ddd         2017-10-23 16:56:34

Here My date column datatype is datetime and my user input is string like 2017-10-23 . Here I need query to fetch data from table after formatting the user input date.

You can use the mysql's DATE() function to compare only the date and not the time.

eg.: select * from table where date(date) = '2017-10-23'

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