jeg prøvede lige at kører dette script:
<?php
$mysqli = new mysqli('localhost', 'root', '', "test");
$sql = "DELETE FROM sogning WHERE DATE(dato) < DATE( DATE_SUB(NOW(), INTERVAL 30 DAY) )";
$query = mysqli_query( $mysqli, $sql );
?>
tabel før
CREATE TABLE `sogning` (
`id` int(11) NOT NULL,
`dato` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;
INSERT INTO `sogning` (`id`, `dato`) VALUES
(1, '2017-08-01'),
(2, '2017-07-01'),
(3, '2017-06-01'),
(4, '2017-08-02');
ALTER TABLE `sogning`
ADD PRIMARY KEY (`id`);
ALTER TABLE `sogning`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;COMMIT;
tabel efter
CREATE TABLE `sogning` (
`id` int(11) NOT NULL,
`dato` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;
INSERT INTO `sogning` (`id`, `dato`) VALUES
(1, '2017-08-01'),
(4, '2017-08-02');
ALTER TABLE `sogning`
ADD PRIMARY KEY (`id`);
ALTER TABLE `sogning`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;COMMIT;
dvs den slettede dem der var mere end 30 dage gamle, hvilke også var meningen