Jump to content
Sign in to follow this  
BrainPill

DELETE records before specific time

Recommended Posts

Quote

SELECT * FROM `my_tab`

 

 

rec_nr  form_nr              nonce_number                               login_time                          ip_fict                   created_on      

1             3101255               5a71b1d6dcb71                                1517400534                        12.34.5.0              2018-01-31 13:08:54      

2             9069570               5a71b319adc72                                1517400857                        12.34.5.0             2018-01-31 13:14:17      

3             7399905               5a71fd2075ce8                                1517419808                        12.34.5.0             2018-01-31 18:30:08      

4             8635151               5a71fd2904493                                1517419817                        12.34.5.0             2018-01-31 18:30:17      

5             9956260               5a72a96e8f080                                1517463918                        12.34.5.0             2018-02-01 06:05:18      

6             1679771               5a72a975bc0c3                                 1517463925                        12.34.5.0             2018-03-02 06:40:25      

7             9342245               5a72a97c52a5e                                 1517463932                        12.34.5.0             2018-03-02 06:45:32      

8             2744250               5a72fe0149614                                1517485569                        12.34.5.0             2018-03-02 12:46:09      

9             1954005               5a72fe92a4f09                                 1517485714                        12.34.5.0             2018-03-02 12:48:34      

10           7756038               5a7300125b748                                1517486098                        12.34.5.0             2018-03-02 12:54:58      

Hi.

This is the table output I have while using SELECT.

Now I want to DELETE all records , except those from the last 3 hours.

I tried mysql combined with now() and I tried this:


SELECT * FROM `my_tab` WHERE SEC_TO_TIME(-10800) > `created_on` 

 If someone can give the right setup how to do this in PHP/MYSQL then I would be very happy.

 

 

 

 

Share this post


Link to post
Share on other sites

You can use the condition `created_on` < DATE_SUB(NOW(), INTERVAL 3 HOUR). It uses the DATE_SUB() function.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...