What is the most effective way to get all records with the field datetime, which is somewhere between yesterday 00:00:00and yesterday 23:59:59?
00:00:00
23:59:59
Table:
id created_at 1 2016-01-19 20:03:00 2 2016-01-19 11:12:05 3 2016-01-20 03:04:01
Suppose yesterday was 2016-01-19, then in this case all I would like to return is lines 1 and 2.
Since you are only looking for a part of the date, you can easily compare it using the MySQL DATE()function . Please note that if you have a very large number of entries, this may be ineffective; the benefits of indexing are lost with the derived value DATE().
DATE()
SELECT * FROM table WHERE DATE(created_at) = DATE(NOW() - INTERVAL 1 DAY);
,
SELECT * FROM TABLE WHERE CREATED_AT >= CURDATE() - INTERVAL 1 DAY AND CREATED_AT < CURDATE();
: subdate(current_date, 1)
subdate(current_date, 1)
!
. , subdate(), .
subdate(currentDate, 1)
, .
select * from tablename where created_at between subdate(CURDATE(), 1) and date (now() )
subdate, "", date(), , , . :
subdate
date()
SELECT * FROM tablename WHERE DATE(created_at) = SUBDATE(CURRENT_DATE(), INTERVAL 1 DAY)
Source: https://habr.com/ru/post/1625240/More articles:Firefox Error Using JS Video - video.jsHow to fix this compilation error for comparing std :: chrono in C ++ 11? - c ++Elasticsearch: оценка расстояния по расстоянию и возврату без вычисления расстояния в два раза - elasticsearchHow to use BeautifulSoup to get deeply nested div values? - pythonPrintWriter - a new line. Works great in Eclipse - javaHow to calculate grades from script_fields in elasticsearch? - elasticsearchProgrammatically change focus after entering text in UITextfield - objective-cthe compiler asked me to enable the return statement, although I already included it - javaYouTube Channel Subscription for Android - androidIs it true that JOINS can be used everywhere to replace subqueries in SQL - sqlAll Articles