本文介绍了MySQL日期搜索MM / DD / YYYY到MM / DD / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL中有一张表,如下所示:

  date | storenum | views 
- -----------------------------
08/21/2009 | 42 | 3
---- ---------------------------
08/22/2009 | 43 | 1
------ -------------------------
08/21/2009 | 43 | 4
-------- -----------------------
08/22/2009 | 42 | 22
---------- ---------------------

我知道这是一个非常规的日期格式,但是我使用它而不是YYYY-MM-DD来方便使用。但是我必须搜索这个数据库才能得到两个日期之间的所有查看记录。一般来说,它是有效的,但是当我从日期如01/01/2009到01/01/2010进行搜索时,我没有得到任何结果。有没有人有任何建议吗?



欢迎建设性批评。谢谢!

解决方案

诚实地,改变你的存储方式。但是,为了处理现在的事情,您可以使用将这些转换为MySQL可以使用的日期。


I have a table in MySQL That looks like the following:

date        |storenum   |views
-------------------------------
08/21/2009  |42         |3
-------------------------------
08/22/2009  |43         |1
-------------------------------
08/21/2009  |43         |4
-------------------------------
08/22/2009  |42         |22
-------------------------------

I know that this is an unconventional date format, but I am using it as opposed to YYYY-MM-DD for ease of use. Yet i have to search this database to get all "View Records" Between two dates. In general it works but when I search from a date such as 01/01/2009 to 01/01/2010 I get no results.

Does anyone have any suggestions? Constructive criticism is welcome. Thanks!

解决方案

In all honesty, change the way you store dates. But for working with what you have now, you could look into using STR_TO_DATE() to convert these to dates that MySQL can work with.

这篇关于MySQL日期搜索MM / DD / YYYY到MM / DD / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:54