MySQL time functions date_sub (), weekday (), curdate ()

date_sub 
meaning: interval from the date minus a specified time. 
syntax: SELECT DATE_SUB (date, INTERVAL expr unit) 
Case: the SELECT date_sub (CURDATE (), INTERVAL WEEKDAY (CURDATE ()) - 26 DAY) 

Date representation: Year - Month - day 
time representation: Year - month - day hours: minutes: seconds 

Interpretation: 
the SELECT CURDATE (); # get the current date
 the SELECT wEEKDAY (CURDATE ()); return a date weekday index value #WEEKDAY function, that is Monday 0, 1 Tuesday, Sunday is 6.
SELECT WEEKDAY (CURDATE ()) - 26 is ;
 SELECT DATE_SUB ( ' 2020-02-24 ' , the INTERVAL 26 is DAY); # current date minus 26 days period
 SELECT DATE_SUB ( ' 2020-02-24' , The INTERVAL - 26 is DAY); # current date minus 26 days minus the time, i.e., plus 26 days

 

Guess you like

Origin www.cnblogs.com/smileblogs/p/12355903.html