Computers & ProgrammingBackend DevelopmentSQL

MySQL DATE Function

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top