What is the difference between NOW()
and DATE(NOW())
in terms of performance, results and precision? How will MySQL understand those 2 functions?
NOW()和DATE(NOW())在性能,结果和精度方面有什么区别? MySQL将如何理解这两个功能?
I was wondering what is the best between
我想知道什么是最好的
WHERE the_date < NOW()
and
WHERE the_date < DATE(NOW())
3 个解决方案
#1
1
NOW() returns current date/time. DATE(NOW()) returns the date part. If you want to know only the date, use CURRDATE().
NOW()返回当前日期/时间。 DATE(NOW())返回日期部分。如果您只想知道日期,请使用CURRDATE()。
#2
1
You are looking at two different comparisons.
您正在寻找两种不同的比较。
Since the_date
contains a time of day, the expression the_date < NOW()
will take into account the time of day at the moment you execute the SQL statement, which could make a difference if the YYYY-MM-DD in the_date
is the same as the current datetime.
由于the_date包含一天中的某个时间,因此表达式the_date
In the case of the_date < DATE(NOW())
, you are comparing the_date
to YYYY-MM-DD 00:00:00000
, so the current time of day from NOW()
is ignored and set to midnight.
在the_date
What is more important here is what you need to do and what results you are expecting.
这里更重要的是你需要做什么以及你期望得到什么结果。
#3
0
The DateTime.Now
property returns the current date and time, for example 2011-07-01 10:09.45310
.
DateTime.Now属性返回当前日期和时间,例如2011-07-01 10:09.45310。
The DateTime.Today
property returns the current date with the time components set to zero, for example 2011-07-01 00:00.00000
.
DateTime.Today属性返回时间组件设置为零的当前日期,例如2011-07-01 00:00.00000。
The DateTime.Today
property actually returns DateTime.Now.Date
:
DateTime.Today属性实际上返回DateTime.Now.Date:
#1
1
NOW() returns current date/time. DATE(NOW()) returns the date part. If you want to know only the date, use CURRDATE().
NOW()返回当前日期/时间。 DATE(NOW())返回日期部分。如果您只想知道日期,请使用CURRDATE()。
#2
1
You are looking at two different comparisons.
您正在寻找两种不同的比较。
Since the_date
contains a time of day, the expression the_date < NOW()
will take into account the time of day at the moment you execute the SQL statement, which could make a difference if the YYYY-MM-DD in the_date
is the same as the current datetime.
由于the_date包含一天中的某个时间,因此表达式the_date
In the case of the_date < DATE(NOW())
, you are comparing the_date
to YYYY-MM-DD 00:00:00000
, so the current time of day from NOW()
is ignored and set to midnight.
在the_date
What is more important here is what you need to do and what results you are expecting.
这里更重要的是你需要做什么以及你期望得到什么结果。
#3
0
The DateTime.Now
property returns the current date and time, for example 2011-07-01 10:09.45310
.
DateTime.Now属性返回当前日期和时间,例如2011-07-01 10:09.45310。
The DateTime.Today
property returns the current date with the time components set to zero, for example 2011-07-01 00:00.00000
.
DateTime.Today属性返回时间组件设置为零的当前日期,例如2011-07-01 00:00.00000。
The DateTime.Today
property actually returns DateTime.Now.Date
:
DateTime.Today属性实际上返回DateTime.Now.Date: