Answer the question
In order to leave comments, you need to log in
How to delete specific records from MySQL by datetime?
Good afternoon ! )
There is an ACS database where access reports arrive, the problem is that it is necessary to delete records from the database that are identical in time + -20 seconds related to the same employee, while there can be many of them.
For example:
if the mark is before 13 o'clock
SELECT lg.lastname,lg.firstname, lg.time
FROM acc_monitor_log as lg
WHERE lg.lastname in (SELECT lastname FROM acc_monitor_log
WHERE(time < lg.time and time > DATE_ADD(lg.time,INTERVAL -20 SECOND))
OR (time > lg.time AND time < DATE_ADD(lg.time,INTERVAL 20 SECOND))
AND lastname = lg.lastname) AND LENGTH(lg.lastname) > 1
ORDER BY time DESC
Answer the question
In order to leave comments, you need to log in
$DATE = date("H:m:s", strtotime($row['date']));
As you can see you can convert date to seconds.
Then it's a matter of two minutes, in a loop we check all the records that match in hours, then in minutes, then in seconds.
And we leave only the first. All
php.net/manual/en/function.date.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question