Languages

MySQL - how to display date values without time?

0 points
Asked by:
martineau
210

I'm doing date comparison in MySQL and I want to display date values without time.

Example:

I want to have 2020-01-01 instead of 2020-01-01 00:00:00.

How to get rid of the 00:00:00 part?

My code:

SELECT `event_date`
FROM `events`
WHERE `event_date` <= '2020-01-04';
1 answer
0 points
Answered by:
martineau
210

Use the DATE() function.

Syntax:

SELECT DATE('YYYY-MM-DD');

Where: 

  • YYYY - four-digit year format, e.g. 2021,
  • MM - month number (counted from 01 to 12),
  • DD - day number (from 01 to 31 - depending on month),

So your code will look like this:

SELECT DATE(`event_date`)
FROM `events`
WHERE `event_date` <= '2020-01-04';
0 comments Add comment
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join