MySQL Query the time period of the data MySQL query based on the timestamp of the specified date not everyone will, the following is a way for you to introduce a MySQL query time period, for your reference, I hope you can enlighten.
Select Now ()--current date and time 2018-07-25 14:29:36select last_day (' 2018-02-01 '); --Returns the last day of the month 2018-02-28select Date_format (now (), '%y-%m-%d%h:%m:%s ')--formatted output 2018-07-25 14:07:18select ' 2018-07-25 ' = ( Select Date_format (now (), '%y-%m-%d ')); --to determine whether the current date is equal to the specified date, return 0 for unequal, 1 for equal 1set @dt = (SELECT date_format (now (), '%y-%m-%d%h:%i:%s ')); --Formats the current date and time and assigns a value to the @dt SELECT @dt;--2018-07-25 14:33:50select Date (@dt);--2018-07-25select time (@dt); --14:33:50select DATE (now ()); --only output the current date 2018-07-25select time (now ()); --Only output current time 14:36:19select year (now ()); --2018select month (now ()); --7select Day (now ()); --25select Time (now ()) Time1, Sleep (3), Time (now ()) time2; --Middle sleep 3s clock time1 and time2 are the same time 14:43:54014:43:54select times (Sysdate ()) Time1,sleep (3), Temporal (sysdate ()) time2; --Middle sleep 3s clock time1 and time2 time difference 3s 14:43:15014:43:18--other functions to get the current date and time select Current_date,current_time,current_user, Localtime,localtimestamp,date (localtime), date (Localtimestamp), Time (localtime);-- 2018-07-2514:48:30root@localhost2018-07-25 14:48:302018-07-2514:48:302018-07-252018-07-2514:48:30set @dt = ' 2018-02-14 14:22:23 '; SELECT dayofmonth (' 2018-02-14 ')--the day of January 14SELECT DAYOFWEEK (' 2018-02-14 ')--the day of the week Note: 4SELECT dayofyear from Sunday (@dt)-- Day of the Year 45select WeekOfYear (@dt)--Week 7 of the year
Format the date value according to the format string:
%s,%s two digits in seconds (00, 01, ..., 59)
%I,%I two digits in the form of points (00, 01, ..., 59)
%H two-digit hours, 24 hours (00,01, ..., 23)
%h Two-digit hours, 12 hours (01,02, ..., 12)
%k digital form of hours, 24 hours (0,1, ..., 23)
%l digital form of hours, 12 hours (1, 2, ..., 12)
%T 24-hour time form (HH:MM:SS)
%r 12-hour time format (hh:mm:ss AM or Hh:mm:ss PM)
%p am or PM
%W the name of each day of the week (Sunday, Monday, ..., Saturday)
%a the abbreviation of the name of each day of the week (Sun, Mon, ..., Sat)
%d two digits for the number of days in the month (xx,,..., 31)
%e number representation of days in the month (1, 2, ..., 31)
%d The English suffix indicates the number of days in the month (1st, 2nd, 3rd,... )
%w number of days in the week (0 = Sunday, 1=monday, ..., 6=saturday)
%j three-digit number of days in the year (001, 002, ..., 366)
%u weeks (0, 1, 52), where Sunday is the first day of the week
%u weeks (0, 1, 52), where Monday is the first day of the week
%M month name (January, February, ..., December)
%b Abbreviated month name (January, February,...., December)
%m Two digit month (01, 02, ..., 12)
The month of%c numbers (1, 2, ...., 12)
%Y Four-digit year
%y Two-digit year
Percent direct value "%"
Related articles:
MySQL query timestamp and date conversion
MySQL time and date Query method and function
Related videos:
PHP make lunisolar conversion Calendar plugin