Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从我的数据库中显示一些结果(名称、描述等字段),将所选日期与数据库中行的时间戳进行比较。
在我的数据库中,该字段start具有这种形式的时间戳2013-07-30 23:00:00。当我搜索表单时,$selected日期的格式与2013-07-30 13:50:00
start
2013-07-30 23:00:00
$selected
2013-07-30 13:50:00
但是,我想显示匹配同一天和同一个月的结果,忽略时间,但我不知道如何使用 PDO 语句来做到这一点。喜欢比较2013-07-30唯一。
2013-07-30
我已经连接了我的数据库,并且可以通过示例执行非常基本的查询。
谢谢你。
将您的 DATETIME 转换为 DATE,然后进行验证:
CAST(tablename.datetime AS DATE) as startDate
你尝试过这样的事情吗?
$sh = $db->prepare('SELECT * FROM table WHERE DATE(`start`) = DATE(:start)'); $sh->bindValue(":start", $selected); $sh->execute();