我使用当前日期从MySQL表中获取数据,但它显示零行
我的表结构是
ActivityTypeID int(11) No auto_increment
ActivityTypeCode varchar(20) utf8_general_ci No
ActivityTypeDescription varchar(250) utf8_general_ci No
UserName varchar(50) utf8_general_ci No
AddedDateTime date
查询:
SELECT *
FROM `ActivityTypeLookup`
WHERE AddedDateTime=CURDATE()
表格中的数据如下所示
日期是这样给出的,但是当我在sql中运行此查询时,它显示零记录
2013-06-28
这是输出
5 Video You have uploaded Video to catalog imran.husain 2013-06-28
6 Video You have Played Video workin imran.husain 2013-06-28
答案 0 :(得分:0)
您可以使用Date_Format功能确保查询中的日期格式相同
编辑:
Select *
From ActivityLookup
where date_Format(addedDateTime, "%Y-%m-%d") = date_Format(Now(), "%Y-%m-%d")
编辑2:
好吧,我仍然无法理解为什么你没有得到预期的输出,我创建了相同的表并插入了类似的数据,我得到了所需的输出。 PFB我在SQL Fiddle上使用的SQL命令。
Create table ActivityTypeLookup(activityId int, activitytype varchar(20), activitydescription varchar(200), username varchar(20), addedDateime date);
insert into ActivityTypeLookup values(1, "Activity 1", "sth", "some user", date_Format("2013-02-23", "%y-%m-%d"));
insert into ActivityTypeLookup values(2, "Activity 2", "sth", "some user", date_Format("2013-06-23", "%y-%m-%d"));
insert into ActivityTypeLookup values(3, "Activity 1", "sth", "some user", date_Format("2013-06-28", "%y-%m-%d"));
Select * from ActivityTypeLookup
where
date_format(addedDateime, "%Y-%m-%d") = date_format(Now(), "%Y-%m-%d");
答案 1 :(得分:-1)
您可以使用date()
功能根据您的日期过滤日期
$date = date('Y-m-d',time()); //it will give to you current date with same format
SELECT *
FROM `ActivityTypeLookup`
WHERE AddedDateTime='$date'