Did you find this useful?
Socialize it today.


MySQL DATE Function

Saturday, December 24, 2011

tags SQL

The MySQL DATE function extracts the date part of a date or date/time expression. The equivalent function in Microsoft SQL Server is somewhat DATEPART, but the CONVERT function may provide a better result depending on the required format.

Employees Table

employeeIDemployeeNameaccountCreated
1000John Smith1995-12-03 13:23:30.657
1001Fred White2001-10-12 09:41:44.125
1002Jane Scott1998-05-01 11:36:16.334
1003Samuel Williams1991-01-03 15:19:51.293

In this example, we want to find out what date the employees' accounts were created.


Syntax

DATE(date)


Example
SELECT employeeName as [Employee Name], DATE(accountCreated) as [Acc Created]
FROM employees


Results

Employee NameAcc Created
John Smith1995-12-03
Fred White2001-10-12
Jane Scott1998-05-01
Samuel Williams1991-01-03

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook