MySQL gets the first day of the quarter of this month, the first day of the week the SQL statement

Source: Internet
Author: User

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


MySQL Tutorials > 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 the MySQL statement

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


Get the first day of the quarter with the MySQL statement

Date
Concat (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 the MySQL statement:
Optimization:
Date
Concat (Year (Curdate ()), '-', ELT (quarter (Curdate ()), 1,4,7,10), '-', 1)


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

MySQL Gets the same day publish file content SQL statement

SELECT * from ' p8_memberdata ' where RegDate BETWEEN (Unix_timestamp (Today ()) -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

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.