如何在php中使用两个不同的日期从数据库中获取数据? [英] How to fetch data from database using two different date in php?
问题描述
date1 = 10/1/2015日期 2 = 10/13/2015`
如何使用这两个日期从数据库中获取数据?我想获取从 10 月 1 日到 13 日输入的所有数据.我如何使用 php 或 SQL 来做到这一点?请指导我编写 SQL 查询.
数据库设计
id 名称 日期1 只公羊 10/1/20152 shyam 10/2/20153 哈里 2015/10/134 gita 10/14/2015
我想选择并显示在 1st oct
到 13th oct
之间列出的前 3 个 id,并且不想显示 14th oct 值.请帮我.期待帮助.先感谢您.:)
MySQL 中的日期格式是 yyyy-MM-dd
.所以,查询应该是 -
select * from test where date '2015-10-01' and '2015-10-13';
如果您想使用不同的格式来获取数据,那么您可以使用 STR_TO_DATE
.您的查询将如下所示.
select * from test where date 在 STR_TO_DATE('26-10-2012', '%d-%m-%Y') 和 STR_TO_DATE('28-10-2012', '%d-%我的');
date1 = 10/1/2015
date2 = 10/13/2015`
How to fetch data from database using these two dates? I want to fetch all the data that was entered from 1 to 13 october. How can I do it using php or SQL? Please guide me to write the SQL queries.
Database design
id name date
1 Ram 10/1/2015
2 shyam 10/2/2015
3 hari 10/13/2015
4 gita 10/14/2015</pre>
I want to select and show first 3 id which are listed between 1st oct
to 13th oct
and don't want to show 14th oct value. Please help me. Looking forward for the help. Thank you in advance. :)
Date format in MySQL is yyyy-MM-dd
. So, the query should be -
select * from test where date between '2015-10-01' and '2015-10-13';
If you want to use a different format to fetch your data then you can use STR_TO_DATE
. Your query will look like this.
select * from test where date between STR_TO_DATE('26-10-2012', '%d-%m-%Y') and STR_TO_DATE('28-10-2012', '%d-%m-%Y');
这篇关于如何在php中使用两个不同的日期从数据库中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!