What is the SQL DATE() function?

SQL DATE() function enables us to access the date value from the particular historical or current timestamp values.

Let us consider an example to understand the same.

Consider a small scale company, wherein a record of the attendance of the employees is being maintained in the form of a database. If the supervisor wishes to check for the days on which a particular employee is absent, the developer can run the DATE() function on the attendance database and help the supervisor with the date values of the same.

So, we can say that the DATE() function helps us extract the date values from the provided datetime expression.

Let us now understand the structure of DATE() function.


Syntax of DATE() function

The Date() function returns the date extracted from the passed datetime expression to it.

DATE(datetime expression)

The function returns NULL, if the passed argument is not a date or datetime expression.

Having understood the working of DATE() function, let us now implement the same through some examples.


Implementing DATE() function through examples

In the below example, we have passed a datetime expression. The DATE() function extracts the date value from the expression.

SELECT DATE("2020-06-07 11:43:21");

Output:

2020-06-06T22:00:00.000Z

In this example, we have violated the standard format of the datetime expression and thus the function returns NULL.

SELECT DATE(" DATE: 2020-06-07 11:43:21");

#sql #date() function #date

What is SQL DATE() function?
1.20 GEEK