About Mysql date selection problem

WBOY
Release: 2016-07-06 13:53:29
Original
1120 people have browsed it

The name of my database time field is create_time, and the type is TimeStamptype

Now I want to get yesterday’s data~ For example, the time in the data is 2016-06-15 03:28:07
I used the following statement
TO_DAYS(NOW()) - TO_DAYS(create_time) <= 1

The current computer time is 2016-06-15 13:45:12

The data is still displayed, but it should be impossible to find out... It stands to reason that the data on June 14, 2016 should be found...
Why is this sentence useless?

Reply content:

The name of my database time field is create_time, and the type is TimeStamptype

Now I want to get yesterday’s data~ For example, the time in the data is 2016-06-15 03:28:07
I used the following statement
TO_DAYS(NOW()) - TO_DAYS(create_time) <= 1

The current computer time is 2016-06-15 13:45:12

The data is still displayed, but it should be impossible to find out... It stands to reason that the data on June 14, 2016 should be found...
Why is this sentence useless?

Why should it be less than or equal to 1? Wasn’t it equal to 1 yesterday?

The date format you save is a timestamp, just write it like this:
TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(create_time)) = 1

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template