Code :
- SET
- @debut = last_day(current_date() - interval 7 month) + interval 1 day,
- @fin = last_day(current_date() - interval 1 month) + interval 1 day;
- CREATE TABLE `test` (
- `id` int(11) NOT NULL,
- `date` timestamp NOT NULL,
- `commentaire` varchar(10) NOT NULL
- );
- ALTER TABLE `test`
- ADD PRIMARY KEY (`id`),
- ADD KEY `date` (`date`);
- INSERT INTO `test`(`id`, `date`, `commentaire`) VALUES
- ('1', '2023-09-30 01:23:45', 'trop tôt'),
- ('2', '2023-10-01 01:23:45', 'ok'),
- ('3', '2023-11-11 01:23:45', 'ok'),
- ('4', '2023-12-12 01:23:45', 'ok'),
- ('5', '2024-01-01 01:23:45', 'ok'),
- ('6', '2024-02-02 01:23:45', 'ok'),
- ('7', '2024-03-31 01:23:45', 'ok'),
- ('8', '2024-04-01 01:23:45', 'trop tard');
- SELECT @debut, @fin;
- SELECT * FROM `test` WHERE `date` >= @debut AND `date` < @fin;
|