How does mysql obtain the first day of the first week of this month? solution ---------------- I just want to talk about my thoughts: SQL statement efficiency problems, try to use mysql functions as few as possible in SQL statements, so it is better to splice SQL statements and directly query more efficiently! You concatenate the first day of the first week of each month in the language you are good at, and then query-how does mysql obtain the number of the first day of the first week of this month?
How does mysql obtain the first day of the first week of this month?
------ Solution --------------------
I just want to talk about my thoughts:
SQL statement efficiency problem, try to use mysql functions as few as possible in SQL statements, so it is better to splice SQL statements and directly query more efficiently!
You splice the first day of the first week of each month in your preferred language and then query
------ Solution --------------------
Haha, this can be used for exercises. you can familiarize yourself with the datetime series functions of mysql,
Do not rush to close the post to see who can write the simplest (the requirement is to return the datetime type value of the first Monday of the month on a certain date)
I get one of the following:
Set @ a = '2017-12-31 '-- this is just for convenience. you can also directly write the date into the SQL
;
Select date_add (last_day (date_sub (@ a, interval 1 month )),
Interval dayofmonth (date_sub (last_day (@ a), interval weekday (last_day (@ a) % 7 day)
As result
;
In addition, this is very simple in php and can be written as follows:
Echo date ('Y-m-D', strtotime ('First Monday of 2010-12-24 '));