MySQL YEARWEEK function (to) bitsCN.com
-
MySQL YEARWEEK function and query data of this week
-
16:45:10 am I want to talk about two sentences: kamui.pdf
-
Add to favorites I want to contribute
-
The YEARWEEK function of MySQL and the YEARWEEK function for querying the data of this week MySQL is a function for obtaining the year and the number of weeks. The function form is YEARWEEK (date [, mode]).
For example, on Sunday www.bitsCN.com select yearweek ('2017-3-14 '), 11 select yearweek ('2017-3-14', 1) returns 10
The second parameter is mode, which means: www.bitsCN.com ModeFirst day of weekRangeWeek 1 is the first week... 0Sunday0-53with a Sunday in this year1Monday0-53with more than 3 days this year2Sunday1-53with a Sunday in this year3Monday1-53with more than 3 days this year4Sunday0-53with more than 3 days this year5Monday0-53with a Monday in this year6Sunday1-53with more than 3 days this year7Monday1-53with a Monday in this year queries the data of the current week SELECT name, submittime FROM enterprise where yearweek (date_format (submittime, '% Y-% m-% d') = YEARWEEK (now (); query last week's data SELECT name, submittime FROM enterprise where yearweek (date_format (submittime, '% Y-% m-% d') = YEARWEEK (now ()-1; query the data of the current month select name, submittime from enterprise where date_format (submittime, '% Y-% M') = date_format (now (),' % Y-% M ') query the select name, submittime from enterprise where submittime between date_sub (now (), interval 6 month) and now () of data from the current six months; query the select name of the data from the previous month, submittime from enterprise where date_format (submittime, '% Y-% M') = date_format (DATE_SUB (curdate (), INTERVAL 1 MONTH),' % Y-% M '); select * from 'user' where DATE_FORMAT (pudate, '% Y % M') = DATE_FORMAT (CURDATE (),' % Y % M '); select * from user where WEEKOFYEAR (FROM_UNIXTIME (pudate, '% y-% m-% d') = WEEKOFYEAR (now ()); select * from user where MONTH (FROM_UNIXTIME (pudate, '% y-% m-% d') = MONTH (now ()); select * from [user] where YEAR (FROM_UNIXTIME (pudate, '% y-% m-% d') = YEAR (now () and MONTH (FROM_UNIXTIME (pudate, '% y-% m-% d') = MONTH (now (); select * from [user] where pudate between last day of last MONTH and first day of next MONTH;
BitsCN.com