The date_format and STR_TO_DATE of MYSQL are recently used in the project. Have a good time with the MYSQL date conversion function. The process is as follows:
Take the current year: SELECT DATE_FORMAT (CURDATE (), '% Y year'); output: SELECT DATE_FORMAT (CURDATE (), '% Y % mmonth'); output: Week number of the current year in month 1, 07th: SELECT DATE_FORMAT (CURDATE (), '% Y % u week'); output: Week 1, 28th
OK. Are you sure you want to get all of them? What's better: After you get them, I wonder if I can turn them back? Start now! Convert 2013 to the time object:
SELECT STR_TO_DATE (year (CURDATE (), "% Y") = STR_TO_DATE ('August 1', "% Y years"); output: 1
It seems that there is a drama! Continue to change the date of January 1, 07th to the following:
SELECT date_format (CURDATE (), "% Y-% m") = date_format (STR_TO_DATE ('1970, 07th month', "% Y % m month "), "% Y-% m"); output: 1
No problem! Continue to set the 28th turnover time in April as follows:
SELECT date_format (CURDATE (), "% Y-% u") = date_format (STR_TO_DATE ('Week 2013, January 1, 28th ', "% Y % u Week "), "% Y-% u"); output: 0
WHY ???? Continue to find the cause and find a magical phenomenon:
SELECT date_format (STR_TO_DATE ('Week 28th, February 11', "% Y % u Week"), "% Y-% u ");
The output result is: 2013-613566753 Q & A has no reference at all. After a long headache, I finally thought of the following solution: I still compared it with the 2013 week of June 28th:
SELECT date_format (CURDATE (), '% y') = date_format (STR_TO_DATE ('1970, 28th Week', "% Y"),' % y ') and date_format (CURDATE (), '% U') = (select SUBSTR ('1970, 28th Week' FROM 7 FOR 2); output: 1MYSQL date_format and STR_TO_DATE
I recently worked on a project and had a good time with the MYSQL date conversion function. The process is as follows:
Take the current year: SELECT DATE_FORMAT (CURDATE (), '% Y year'); output: SELECT DATE_FORMAT (CURDATE (), '% Y % mmonth'); output: Week number of the current year in month 1, 07th: SELECT DATE_FORMAT (CURDATE (), '% Y % u week'); output: Week 1, 28th
Okay. It's nice to get all of them. The better one is as follows: (Hey, everybody can be evil !) After obtaining it, I thought about whether I could turn it back? Start now! Convert 2013 to the time object:
SELECT STR_TO_DATE (year (CURDATE (), "% Y") = STR_TO_DATE ('August 1', "% Y years"); output: 1
It seems that there is a drama! Continue to change the date of January 1, 07th to the following:
SELECT date_format (CURDATE (), "% Y-% m") = date_format (STR_TO_DATE ('1970, 07th month', "% Y % m month "), "% Y-% m"); output: 1
No problem! Continue to set the 28th turnover time in April as follows:
SELECT date_format (CURDATE (), "% Y-% u") = date_format (STR_TO_DATE ('Week 2013, January 1, 28th ', "% Y % u Week "), "% Y-% u"); output: 0
WHY ???? Continue to find the cause and find a magical phenomenon:
SELECT date_format (STR_TO_DATE ('Week 28th, February 11', "% Y % u Week"), "% Y-% u ");
The output result is: 2013-613566753 Q & A has no reference at all. After a long headache, I finally thought of the following solution: I still compared it with the 2013 week of June 28th:
SELECT date_format (CURDATE (), '% y') = date_format (STR_TO_DATE ('1970, 28th Week', "% Y"),' % y ') and date_format (CURDATE (), '% U') = (select SUBSTR ('1970, 28th Week' FROM 7 FOR 2); output: 1