My data inventory may contain timestamp of hour, minute, and second. now there is only one time for comparison between year, month, and day. if the comparison is equal, I will query it. Which of the following experts will guide you how to judge the query? thank you very much. My data inventory may contain timestamp of hour, minute, and second. now, we only need to compare the time every year, month, and day. if they are the same, we will query it. Which of the following experts will guide you how to judge the query? thank you very much.
Reply content:
My data inventory may contain timestamp of hour, minute, and second. now, we only need to compare the time every year, month, and day. if they are the same, we will query it. Which of the following experts will guide you how to judge the query? thank you very much.
There are many methods, but I think you need fuzzy queries. I 'd like to explain a better understanding.
1. use the sorttime function to convert the time that is only "year-month-day" to the timestamp, so that you can get time1 at of the current day;
2. still use the sorttime function to get the + 1 time, or simply add the total number of seconds in one day, the variable name is time2, so there are two time nodes.
3. use between to query all the data of the day.
========== If I understand the error, correct it and change it again ==========
Two methods are introduced. The first method is recommended.
If the year, month, and day are the same, it means to query the data within a certain day and take the initiative to control the time range, for example, to query the data of '2017-10-28 '.
$st = strtotime("2016-10-28");$et = strtotime("2016-10-28 23:59:59");select * from table where date_field between $st and $et
select * from table where FROM_UNIXTIME(date_field,'%Y%m%d') ="2016-10-28"
Below is the save fielddatetime
Formatsql
select * from table where date_field between "2016-10-28" and "2016-10-28 23:59:59"
select * from table where DATE_FORMAT(date_field , '%Y%m%d') ="2016-10-28"
If the date format in the database is the same, use the substr function of MySQL to intercept the data to the day for comparison.
The author's problem is:
Query data of a certain day (such as January 1, October 28, 2016) based on the time field:
= $ Min and time <$ max "; // select * from t where time> = 1477584000 and time <1477670400
If the time field is not stored as a timestamp but in date ('ymdhis ') format, you can do this:
select * from t where time >= 20161028000000 and time < 20161029000000