Time turns into years, days and seconds
Select Date_format (now (), '%y%m%d%h%i%s ')
Time turns into month and day
Select Date_format (now (), '%y%m%d ')
This time last year
Select Date_add (now (), Interval-1 year)
This time last month
Select Date_add (now (), Interval-1 month)
Yesterday at this time
Select Date_add (now (), Interval-1 Day)
After 7 days
Select Date_add (now (), Interval 7 day)
//an hour ago
Select Date_add (now (), INTERVAL-1 Hour)
//One minute ago
Select Date_add (now (), Interval-1 minute)
// A second ago
Select Date_add (now (), Interval-1 Second)
//Yesterday (Month day)
Select Date_format (Date_add (now (), Interval 1 days), '%y%m%d ')
//The first and last day of the month
Select Date_sub (Date_sub (now (), '%y%m%d '), Interval extract Now ()) – 1 day), Interval 1 month);
Select Date_sub (Date_sub (Date_format (), '%y%m%d '), Interval extract (Day from Now ()), Interval 0 month);
//A string
Select Date_format (Date_add (' 20090605123020 ', Interval minute), '%y%m%d ')
// Week
Select WeekOfYear (now ())
Select WeekOfYear (' 20090606 ')
in MySQL, the ' 20090707123050 ' and ' 20090707 ' The formatted string is converted as a date type.
in MySQL, there is no Oracle-like TO_CHAR (Num,format) function, so it requires special handling when it comes to 0 in front of the number.
such as Select Left (concat (' xx '), @num), 3) displays a three-digit string, @num = 1 o'clock displays 001, and 123 is the display 123.
CONCAT (Year (A.createtime), left (CONCAT (' 0 ', WeekOfYear (A.createtime)), 2))
SQL Date time plus minus a few hours