What's the best way to do following:
最好的方法是:
SELECT * FROM users WHERE created >= today;
Note: created is a datetime field.
注意:create是一个datetime字段。
10 个解决方案
#1
234
SELECT * FROM users WHERE created >= CURDATE();
But I think you mean created < today
但我想你是说《今日创造》
#2
59
SELECT * FROM myTable WHERE DATE(myDate) = DATE(NOW())
Read more: http://www.tomjepson.co.uk/tutorials/36/mysql-select-where-date-today.html
阅读更多:http://www.tomjepson.co.uk/tutorials/36/mysql-select-where-date-today.html
#3
25
SELECT * FROM users WHERE created >= NOW();
if the column is datetime type.
如果列是datetime类型。
#4
12
If 'created' is datetime type
如果“创建”是datetime类型
SELECT * FROM users WHERE created < DATE_ADD(CURDATE(), INTERVAL 1 DAY);
CURDATE() means also '2013-05-09 00:00:00'
CURDATE()也表示“2013-05-09 00:00”
#5
3
SELECT * FROM users WHERE created >= now()
#6
1
If the column have index and a function is applied on the column then index doesn't work and full table scan occurs, causing really slow query.
如果列有索引,并且在列上应用了一个函数,那么索引将不起作用,并且会发生全表扫描,导致查询速度非常慢。
To use index and compare datetime with today/current date, the following can be used.
要使用索引并将datetime与today/current date进行比较,可以使用以下方法。
select * from users
where created >= CONCAT(CURDATE(), ' 00:00:00') && created < CONCAT(CURDATE(), ' 23:59:59')
#7
1
Answer marked is misleading. The question stated is DateTime
, but stated what was needed was just CURDATE()
.
答案明显是误导。声明的问题是DateTime,但是声明所需要的只是CURDATE()。
The shortest and correct answer to this is:
最简短和正确的回答是:
SELECT * FROM users WHERE created >= CURRENT_TIMESTAMP;
#8
0
The below code worked for me.
下面的代码对我有用。
declare @Today date
Set @Today=getdate() --date will equal today
Select *
FROM table_name
WHERE created <= @Today
#9
-1
SELECT * FROM table_name WHERE CONCAT( SUBSTRING(json_date, 11, 4 ) , '-', SUBSTRING( json_date, 7, 2 ) , '-', SUBSTRING(json_date, 3, 2 ) ) >= NOW();
json_date ["05/11/2011"]
json_date(“05/11/2011”)
#10
-4
you can return all rows and than use php datediff function inside an if statement, although that will put extra load on the server.
您可以返回所有的行并在if语句中使用php datediff函数,尽管这会给服务器增加额外的负载。
if(dateDiff(date("Y/m/d"), $row['date']) <=0 ){
}else{
echo " info here";
}
#1
234
SELECT * FROM users WHERE created >= CURDATE();
But I think you mean created < today
但我想你是说《今日创造》
#2
59
SELECT * FROM myTable WHERE DATE(myDate) = DATE(NOW())
Read more: http://www.tomjepson.co.uk/tutorials/36/mysql-select-where-date-today.html
阅读更多:http://www.tomjepson.co.uk/tutorials/36/mysql-select-where-date-today.html
#3
25
SELECT * FROM users WHERE created >= NOW();
if the column is datetime type.
如果列是datetime类型。
#4
12
If 'created' is datetime type
如果“创建”是datetime类型
SELECT * FROM users WHERE created < DATE_ADD(CURDATE(), INTERVAL 1 DAY);
CURDATE() means also '2013-05-09 00:00:00'
CURDATE()也表示“2013-05-09 00:00”
#5
3
SELECT * FROM users WHERE created >= now()
#6
1
If the column have index and a function is applied on the column then index doesn't work and full table scan occurs, causing really slow query.
如果列有索引,并且在列上应用了一个函数,那么索引将不起作用,并且会发生全表扫描,导致查询速度非常慢。
To use index and compare datetime with today/current date, the following can be used.
要使用索引并将datetime与today/current date进行比较,可以使用以下方法。
select * from users
where created >= CONCAT(CURDATE(), ' 00:00:00') && created < CONCAT(CURDATE(), ' 23:59:59')
#7
1
Answer marked is misleading. The question stated is DateTime
, but stated what was needed was just CURDATE()
.
答案明显是误导。声明的问题是DateTime,但是声明所需要的只是CURDATE()。
The shortest and correct answer to this is:
最简短和正确的回答是:
SELECT * FROM users WHERE created >= CURRENT_TIMESTAMP;
#8
0
The below code worked for me.
下面的代码对我有用。
declare @Today date
Set @Today=getdate() --date will equal today
Select *
FROM table_name
WHERE created <= @Today
#9
-1
SELECT * FROM table_name WHERE CONCAT( SUBSTRING(json_date, 11, 4 ) , '-', SUBSTRING( json_date, 7, 2 ) , '-', SUBSTRING(json_date, 3, 2 ) ) >= NOW();
json_date ["05/11/2011"]
json_date(“05/11/2011”)
#10
-4
you can return all rows and than use php datediff function inside an if statement, although that will put extra load on the server.
您可以返回所有的行并在if语句中使用php datediff函数,尽管这会给服务器增加额外的负载。
if(dateDiff(date("Y/m/d"), $row['date']) <=0 ){
}else{
echo " info here";
}