简体   繁体   English

使用准备好的语句选择其他日期

[英]seletc date query using prepared statement

In the database same date is multiple time there. 在数据库中,同一日期是多个时间。 The table data contain date with time if I use this it is not giving the record that I need to modify. 如果我使用此数据,则表数据中包含带时间的日期,它没有给出我需要修改的记录。 I want 2012-11-21 this date all records. 我要2012-11-21这个日期所有记录。 But token_gen_time it contains 2012-11-21 1:00:00 . 但是token_gen_time它包含2012-11-21 1:00:00 How can I write query to select depending on date. 如何编写查询以根据日期进行选择。

SELECT * FROM mias_log
where activity_status='Token Generated' 
AND token_gen_time='2012-11-21 '

You can drop the time from your token_gen_time using the DATE() function to return values matching only the date 您可以使用DATE()函数从token_gen_time删除时间,以返回仅与日期匹配的值

SELECT * 
FROM mias_log 
where activity_status='Token Generated' 
  AND Date(token_gen_time) = '2012-11-21'

You can extract the date part with DATE() 您可以使用DATE()提取日期部分

SELECT * 
FROM mias_log 
where activity_status = 'Token Generated' 
and date(token_gen_time) = '2012-11-21'

In order to make use of index (if available in token_gen_time), use this 为了利用索引(如果在token_gen_time中可用),请使用此

SELECT * 
FROM mias_log 
where activity_status = 'Token Generated' 
and token_gen_time >= '2012-11-21' 
and token_gen_time < '2012-11-22' 

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

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