Note: The field where the statement last_login_time field names can be replaced with time
# Inquiry yesterday logged-on user account
the SELECT Mobile, last_login_time from the User the WHERE TO_DAYS (the NOW ()) - TO_DAYS (last_login_time) = 1 ; # queries that day to log the user's account
the SELECT Mobile, last_login_time from the User the WHERE TO_DAYS (the NOW ()) - TO_DAYS (last_login_time) < 1 ;
# Search last_login_time value in the last days of recording
the SELECT Mobile, last_login_time from the user the WHERE TO_DAYS (the NOW ()) - TO_DAYS (last_login_time) <= 1 ;
# inquiry last seven days of the logged in user account
the SELECT Mobile , last_login_time from the User the WHERE DATE_SUB (CURDATE (), INTERVAL2 DAY) < DATE (last_login_time);
* explain: INTERVAL 1 DAY, interpreted as the time interval to one day
to log the user in the # queries one week account
the SELECT Mobile, last_login_time from the User the WHERE last_login_time the BETWEEN CURRENT_DATE () - 7 and sysdate (); # queries logged-in user's account this month
the SELECT Mobile, last_login_time from the user the WHERE the DATE_FORMAT (last_login_time, ' % the Y-% M ' ) = the DATE_FORMAT (CURDATE (), ' % the Y-% M ' ); # queries on January Log In Username
the SELECT Mobile, last_login_time from the user the WHEREPERIOD_DIFF (DATE_FORMAT (now (), ' % the Y% m ' ), DATE_FORMAT (last_login_time, ' % the Y% m ' )) = . 1 ;
Note: If the database time is a UNIX timestamp stored in the form of words, comparison of the time need to be changed to a uniform format;
for DATE_SUB () returns the formatted time: 2019-10-29
required UNIX_TIMESTAMP () conversion UNIX timestamp comparison form:
code is as follows:
WHERE inputtime> UNIX_TIMESTAMP (for DATE_SUB (CURDATE (), the INTERVAL. 1 DAY))
(. 1 ) WEEKDAY (date) action: Returns the index date of the week ( 0 = catalog on Monday, . 1 = on Tuesday, ... . 6 = the Sunday) the SELECT WEEKDAY ( ' 1997 - . 11 - 05 '); return: -> 2 (2 ) DAYOFMONTH (date)
action: returns the date is the first day of the month, the range of 1 to 31 is:
MySQL> DAYOFMONTH the SELECT ( '1998-02-03');
return result: ->. 3
(. 3) DAYOFYEAR (date )
action: returns the date is the first day of the year, the range 1 to 366:
MySQL> DAYOFYEAR the SELECT ( '1998-02-03');
return result: -> 34 is
(. 4) DAYNAME (date)
Role: Return date weekday name:
mysql> SELECT DAYNAME("1998-02-05");
-> ’Thursday’
(5)MONTHNAME(date)
Role: Return date month name:
mysql> SELECT MONTHNAME("1998-02-05");
-> ’February’
(6)QUARTER(date)
作用:返回 date 在一年中的季度,范围为 1 到 4:
mysql> SELECT QUARTER(’98-04-01’);
-> 2