MySQL date add minus SQL query statement

Source: Internet
Author: User
Tags mysql tutorial

Work needs to query this month, the data this month to ranking, a closer look at the database tutorial in the database stored in the date format is 2010-02-23 14:2:3 This type, so I think the database by the second query method is not, find a date added to reduce SQL function online DateDiff (Now,oldtime). The test can be done with the following I take my operating process out. [

SELECT * FROM t where DateDiff (now (), senddate) <31 order by click DESC LIMIT 0,10//Query one-month click Data Ranking

SELECT * FROM t where DateDiff (now (), senddate) <7 The order by click DESC LIMIT 0,10//query for one week of data

SELECT * FROM t where DateDiff (now (), senddate) <=1 The order by click DESC LIMIT 0,10//Identify the data for the day

This is more convenient to operate, about the now function, in the MySQL tutorial is recognizable, look at the example below.

Mysql> Select Now ();
+---------------------+
| Now () |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+

OK, now is it convenient to add and subtract the date?

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.