MySQL Forums
Forum List  »  Newbie

Re: How to select all entries of all days between 23:00 and 23:59
Posted by: Barry Galbraith
Date: September 18, 2022 09:04PM

DROP TABLE IF EXISTS `mytable`;

CREATE TABLE `mytable` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `test_date` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ;

/*Data for the table `mytable` */

mysql>insert  into `mytable`(`id`,`test_date`)
values (1,'2022-09-05 12:53:39')
,(2,'2022-09-06 23:53:56')
,(3,'2022-09-07 23:54:15')
,(4,'2022-09-08 12:54:27')
,(5,'2022-09-09 12:54:37')
,(6,'2022-09-10 23:54:43');

SELECT test_date
FROM mytable
WHERE TIME(test_date) BETWEEN "23:00:00" AND "23:59:59";

+---------------------+
| test_date           |
+---------------------+
| 2022-09-06 23:53:56 |
| 2022-09-07 23:54:15 |
| 2022-09-10 23:54:43 |
+---------------------+
3 rows in set (0.00 sec)

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: How to select all entries of all days between 23:00 and 23:59
September 18, 2022 09:04PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.