MySQL 日期之间的日期
我想知道在 MySQL 4.1+ 中是否有一种方法可以查询记录中日期范围之间的特定日期?
举个简单的例子,我有两条带有日期时间范围的记录,就像
ID | Activity | Start Date | End Date
1 Closed 1/1/11 11:00:00 1/4/11 11:00:00
2 Open 1/15/11 10:00:00 1/19/11 09:00:00
我想知道的是,有没有办法获取每条记录的“开始日期”和“结束日期”之间的日期?像这样:
1/2/11、1/3/
11和
1/16/11、1/17/11、1/18/11
或者至少有一种接近这一点并使用 PHP 完成其余部分的方法道路?谢谢!
I am wondering if there is a way, in MySQL 4.1+, to query the specific dates between date ranges in my records?
For a quick example, I have two records with datetime ranges, like
ID | Activity | Start Date | End Date
1 Closed 1/1/11 11:00:00 1/4/11 11:00:00
2 Open 1/15/11 10:00:00 1/19/11 09:00:00
What I want to know is, is there a way I can get the dates between the "Start Date" and "End Date" for each of these records? Like so:
1/2/11, 1/3/11
And
1/16/11, 1/17/11, 1/18/11
Or at least a way to get close to that and use PHP to finish the rest of the way? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能会解决您的问题:
This might sole your problem:
Jordan,
这对于 MySQL 4 来说是不可能的。我认为这个逻辑不应该放在你的数据库层中。
然而,StackOverflow 上有一个与您的问题相关的问题,解决方案是一个存储过程(但为此您需要 mysql 5)。在此处查看:获取两个日期之间的日期列表
我在这个网页上发现了一个尚未准备好使用但合理的方法来解决您的 PHP 问题:
http:// /prajapatinilesh.wordpress.com/2009/05/07/get-all-dates- Between-two-dates-using-php-code/
希望这可以帮助您朝着正确的方向前进。
Jordan,
This is not directly possible with MySQL 4. And i think this logic should not be put in your database layer.
There is however a question on StackOverflow that relates to your problem and the solution is a stored procedure (but for that you need mysql 5). View it here: Get a list of dates between two dates
I found a not ready to use, but sensible approach to your problem in PHP at this web-page:
http://prajapatinilesh.wordpress.com/2009/05/07/get-all-dates-between-two-dates-using-php-code/
Hope this helps you in the right direction.
我之前已经在我自己的 mysql 查询中实现了这一点。
I have implimented this in my own mysql queries before.