将日期作为文本存储在数据库中,但需要查找两个日期之间的记录吗? [英] Storing date as text in database but need to find records between two dates?
问题描述
我将日期作为VARCHAR存储在mysql表中.我实际上有一个发票表,其中存储了发票明细及其日期.我使用php的此功能将这些日期存储在VARCHAR列中.
I am storing dates as VARCHAR in mysql tables. I actually have a invoice table that stores invoice details along with its date. I store those dates with this function of php in VARCHAR column.
date("d/m/y")
现在,我需要生成销售报告,例如从4/5/2012到4/5/2013.我对如何找到日期范围感到困惑.请指导.
Now i need to generate reports of sales like from 4/5/2012 to 4/5/2013. I am confused as to how to find the date range. Please guide.
我正在使用codeigniter.
I am using codeigniter.
推荐答案
如果是日期,为什么不存储为日期?现在,您可以添加另一列,然后使用脚本或程序将经过解析和重组的日期填充到该新列中.因此,您将来的查询可以使用日期数据类型.
If it's dates why not store as date? You could now add another column, then with a script or program populate this new column with the parsed and recomposed dates. Thus, your future queries can work with a date data type.
这篇关于将日期作为文本存储在数据库中,但需要查找两个日期之间的记录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!