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)