简体   繁体   English

如何使用MySQL和PHP格式化按用户输入日期从表中获取数据

[英]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. 我需要使用PHP和MySQL按date从表中获取数据,但是这里的用户输入是string类型。 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 . 在这里,我的date列数据类型是datetime ,我的用户输入是类似于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. 您可以使用mysql的DATE()函数仅比较日期而不是时间。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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