MySQL Date function

Source: Internet
Author: User

today's Time "2016-12-21"

Get Yesterday date Yyyy-mm-dd

Select Date_sub (Curdate (), Interval 1 day)

2016-12-20

Get the month of yesterday

Select Date_format (Curdate (), '%y-%m ')

2016-12

Date condition: History 12 months
Date condition: History 12 months. = = [current day of the month 1th is the end of time], to [the current month before the 12 months of the 1th number] for start time [start, end]

Select Date_format (Date_sub (Curdate (), Interval month), '%y-%m-01 ') as Start_time, Date_format (Curdate (), '%y-%m-01 ' ) as End_time

start_time End_time
2015-12-01 2016-12-01

From the beginning of the month to yesterday. || Number 1th to yesterday [Start, end] month to date | |

Select Date_format (Curdate (), '%y-%m-01 ') as Start_time, Curdate () as End_time

start_time End_time
2016-12-01 2016-12-21

Get Date Yyyymm

Select Extract (Year_month from Curdate ()) as Yyyymm

201612

MySQL Date function

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.