Sample Header Ad - 728x90

Why is it selecting date from another month that requested one?

-2 votes
1 answer
68 views
I have a table that store time begin and time end of some events. I want to search in this table all even that were occuring during specific day. Here is example data: | Id | Date begin | Date End | Name | | -- | ------------------- | ------------------- | ----- | | 1 | 2024-04-18 13:30:45 | 2024-04-18 15:30:45 | 18-04 | | 2 | 2024-04-14 13:30:45 | 2024-04-18 15:30:45 | 18-04 | | 3 | 2024-04-15 13:30:45 | 2024-04-15 15:30:45 | 15-04 | | 4 | 2024-04-14 13:30:45 | 2024-04-14 15:30:45 | 14-04 | | 5 | 2024-04-12 13:30:45 | 2024-04-12 15:30:45 | 12-04 | | 6 | 2024-03-18 13:30:45 | 2024-03-18 15:30:45 | 18-03 | | 7 | 2024-03-15 13:30:45 | 2024-03-16 15:30:45 | 15-03 | | 8 | 2024-03-14 13:30:45 | 2024-03-15 15:30:45 | 14-03 | | 9 | 2024-03-12 13:30:45 | 2024-03-13 15:30:45 | 12-03 | If I want data for the 14/04, this is the excepted output: | Id | Date begin | Date End | Name | | -- | ------------------- | ------------------- | ----- | | 2 | 2024-04-14 13:30:45 | 2024-04-18 15:30:45 | 18-04 | | 4 | 2024-04-14 13:30:45 | 2024-04-14 15:30:45 | 14-04 | Here is my query:
SELECT * FROM content WHERE
    DATE_FORMAT(dateBegin, '%d/%m/%Y') = '14/04/2024'
But here is my actual ouput: | Id | Date begin | Date End | Name | | -- | ------------------- | ------------------- | ----- | | 2 | 2024-04-14 13:30:45 | 2024-04-18 15:30:45 | 18-04 | | 4 | 2024-04-14 13:30:45 | 2024-04-14 15:30:45 | 14-04 | | 8 | 2024-03-14 13:30:45 | 2024-03-15 15:30:45 | 14-03 | Why I get a line from the right day, but of another month ? I made a [Db Fiddle](https://www.db-fiddle.com/f/qasXqfLeEp1a6Mvi7A5Pqu/2) to show this problem. How can I fix it? Note: I'm using MariaDB 10.11.4.
Asked by Elikill58 (181 rep)
Apr 18, 2024, 12:16 PM
Last activity: Apr 18, 2024, 12:46 PM