MySQL gets the first day of the month of the day of the quarter, the first day of the week SQL statements

Source: Internet
Author: User
Tags mysql tutorial string back

Thank you: http://www.111cn.net/database/110/d45124323da8d2d87b80f78319987eda.htm

View another blog on the same topic: http://blog.csdn.net/cleanfield/article/details/41447585

------------------------------------------------------------------------------

The first day of the quarter, and then you can convert the string back to a date. There are many methods, including aliases (synonyms) for the same function. such as Curdate (), Current_date (), current_date, now and so on can return to the same day


MySQL Tutorial > select Curdate (), ELT (QUARTER (Curdate ()),
Year (Curdate ()) *1000+0101,
Year (Curdate ()) *1000+0401,
Year (Curdate ()) *1000+0701,
-year (Curdate ()) *1000+1001) as FIRSTDAYOFQ;
+------------+-------------+
| Curdate () | FIRSTDAYOFQ |
+------------+-------------+
| 2009-05-19 | 2009401 |
+------------+-------------+
1 row in Set (0.00 sec)

Mysql>


Get the first day of the quarter with a MySQL statement

On the first day of this month,
Date
Concat (Year (Curdate ()), '-', Month (Curdate ()), '-', ' 1 '))
The first day of the week
Curdate ()-
WEEKDAY (Curdate ())


Get the first day of the quarter with a MySQL statement

Date
Concat (Year (Curdate ()), '-',
if (Quarter (Curdate ()) =1,1,if (Quarter (Curdate ()) =2,4,if (Quarter (Curdate ()) =3,7,10))


Get the first day of the quarter with a MySQL statement:
Optimization:
Date
Concat (Year (Curdate ()), '-', ELT (quarter (Curdate ()), 1,4,7,10), '-', 1))


The first day of the week
Date_add (Date (' 2009-5-29 '), Interval-weekday (' 2009-5-29 ') day)

MySQL Gets the same day published file content SQL statement

SELECT * from ' p8_memberdata ' where regdate between (Unix_timestamp (now ()) -86440) and now ()
SELECT * from ' p8_memberdata ' WHERE date_format (From_unixtime (regdate), '%y-%m-%d ') = Date_format (now (), '%y-%m-%d ') ORDER BY uid DESC

MySQL gets the first day of the month of the day of the quarter, the first day of the week SQL statement (RPM)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.