MySQL vs. Oracle (ii)---date comparison (MySQL)

Source: Internet
Author: User
Tags date1 getdate

Comparison of date functions between MySQL and Oracle (i)

First, SQL


Short Date format: yyyy-m-d
SELECT REPLACE (CONVERT (varchar), GETDATE (), +), N '-0 ', '-')
Long date format: yyyy mm month DD Day
SELECT STUFF (STUFF (CONVERT (char (8), GETDATE (),), 5,0,n ' year '), 8,0,n ' month ') +n ' Day '
Short Date format: YYYY year M D Day
SELECT Datename (Year,getdate ()) +n ' year ' +cast (DATEPART (Month,getdate ()) as varchar) +n ' month ' +datename (Day,getdate ()) +n ' Day '
Full Date + time format: Yyyy-mm-dd hh:mi:ss:mmm
SELECT CONVERT (char (one), GETDATE (), +convert (char), GETDATE (), 114)

Simple function table (MySQL Server):

GetDate () Returns the current date and time of the system
DateDiff (INTERVAL,DATE1,DATE2) Returns the difference between Date2 and date1 two dates, as specified by interval date2-date1
DATEADD (Interval,number,date) The date specified by interval, plus number
DatePart (Interval,date) Returns the integer value that corresponds to the specified part of the date interval
Datename (Interval,date)

Returns the string name corresponding to the specified part of the date, interval

Example:

1. Return the current date and time of the system

Select getdate ()   // Result: 2017-07-25 09:33:22.230

2. DateAdd returns a new datetime value based on adding a period of time to the specified date

Select dateadd (Day,2,'2017-07-25')    // to date plus 2 days, Results: 2017-07-27 00:00:00.000

3. DateDiff returns the number of date and time boundaries across two specified dates.

Select DateDiff (day,'2017-07-25','2017-07-20')     // Result: 5

4. DatePart returns an integer representing the specified date portion of the specified date.

Select DATEPART (month,'2017-07-25')        // results: 7

5. Datename returns a string representing the specified date part of the specified date

Select ' 2017-07-25 ')      // results: Tuesday


MySQL vs. Oracle (ii)---date comparison (MySQL)

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.