UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(add_time)<=25200
Wherein now () is the current time is other time points add_time 25200: seconds, a difference between now and 7 hours add_time
=============================================================================
Other methods to add time conditions:
Original https://blog.csdn.net/weixin_37632678/article/details/80252364
A: Query time sql server database method
sql server to provide such functions to our inquiry
-
select * from student where YEAR(comeyear)=2015
-
select * from student where month(comeyear)=9
-
select * from student where day(comeyear)=1
-
select * from student where datepart(hh,comeyear)=9
-
select * from student where datepart(mi,comeyear)=9
-
select * from student where datepart(ss,comeyear)=56
-
public class QueryRo { private String beginTime; private String endTime; public String getBeginTime() { return beginTime; } public void setBeginTime(String beginTime) { this.beginTime = beginTime; } public String getEndTime() { return endTime; } public void setEndTime(String endTime) { this.endTime = endTime; }}
Query the sql statement period in the project (time is datetime or date) (time type database):
<if test="beginTime!=null and beginTime!=''"> <![CDATA[ and DATE_FORMAT(tr.add_time, '%Y-%m-%d')>= DATE_FORMAT(#{beginTime}, '%Y-%m-%d') ]]> </if> <if test="endTime!=null and endTime!=''"> <![CDATA[ and DATE_FORMAT(tr.add_time, '%Y-%m-%d') <= DATE_FORMAT(#{endTime}, '%Y-%m-%d') ]]> </if>
Query the sql statement period in the project (time of type VARCHAR) (time type database):
<if test="beginTime!=null and beginTime!=''"> AND tm.add_time>=#{beginTime} </if> <if test="endTime!=null and endTime!=''"> AND tm.add_time <=#{endTime} </if>
& Lt; number of less than <& gt; Greater than>
Attachment:
MySQL DATE_FORMAT () function
Definition and Usage
The DATE_FORMAT () function is used to display the date / time data in different formats.
grammar
DATE_FORMAT(date,format)
date parameter is legitimate date. format predetermined output format of the date / time.
Format that can be used are:
format | description |
---|---|
%a | Abbreviated weekday name |
%b | Abbreviated month name |
%c | Month, the value |
%D | Mid-day with the English prefix |
%d | Day of the month, the value (00-31) |
%e | Day of the month, the value (0-31) |
%f | Microsecond |
%H | Hour (00-23) |
%h | Hour (01-12) |
%I | Hour (01-12) |
%i | Min, value (00-59) |
%j | On the day (001-366) |
%k | Hour (0-23) |
%l | Hour (1-12) |
%M | Month name |
%m | Month, numeric (00-12) |
%p | AM or PM |
%r | Time, 12 hours (hh: mm: ss AM or PM) |
%S | Sec (00-59) |
%s | Sec (00-59) |
%T | Time, 24 hours (hh: mm: ss) |
% U | Week (00-53) Sunday is the first day of the week |
in% | Week (00-53) Monday is the first day of the week |
% V | Week (01-53) Sunday is the first day of the week, and use% X |
% v | Week (01-53) Monday is the first day of the week, with the use of% x |
%W | Weekday name |
%w | Day of the week (0 = Sunday, 6 = Saturday) |
%X | In, where Sunday is the first day of the week, four, and use% V |
%x | In which the first day of the week is Monday, 4, use% v |
%Y | Year 4 |
%Y | Year 2 |
Examples
The following script uses the DATE_FORMAT () function to display different formats. We use the NOW () to get the current date / time:
DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p')
DATE_FORMAT(NOW(),'%m-%d-%Y')
DATE_FORMAT(NOW(),'%d %b %y')
DATE_FORMAT(NOW(),'%d %b %Y %T:%f')
Similar results:
Dec 29 2008 11:45 PM
12-29-2008
29 Dec 08
29 Dec 2008 16:25:46.635