Tags
MySQL , DATE
Asked 3 years ago
22 Sep 2021
Views 628
Kali

Kali posted

MySQL DATE() Function

web-api

web-api
answered Sep 23 '21 00:00

MySQL DATE() function gives the date from the given value.

MySQL DATE() Return value:
DATE() Function return date(YYYY-MM-DD) (only date not time) or null.
on success, it returns the date.
on failure , it returns a NULL value.


MySQL DATE() Examples :


SELECT DATE(CURRENT_TIMESTAMP)

in above MySQL query , we passed current timestamp by constant (CURRENT_TIMESTAMP) and DATE() function convert current timestamp to current date and return date.



SELECT DATE("2021-12-11 12:12:11")

in the above MySQL query, we passed the date and time in string format, and the DATE() function return the date part from DateTime and remove the time part.



SELECT DATE("today is 2021-12-11 12:12:11")

in the above MySQL query, we passed the string which is not in DateTime format, and the DATE() function returns a NULL value.


SELECT DATE("today is 2021-12-11 12:12:11")

in the above MySQL query, we passed the string which is not in DateTime format, and the DATE() function returns a NULL value.


SELECT DATE(now())

in the above MySQL query, we passed the now() as an argument to the DATE() Function and it will return the current date in YYYY-MM-DD.


SELECT DATE(registeration_date)

inin the above MySQL query, we passed the field which has date & time field type, so it returns the date from the given table's field value.

Post Answer