Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:20:36+00:00 2026-06-07T13:20:36+00:00

I have a field in a sql database called time_stamp that timestamps when the

  • 0

I have a field in a sql database called time_stamp that timestamps when the record was added to the database. I have another field called ‘TTL’, which will have either 1, 2, or 3 stored in it (each number within this field represents a day). Can I have a php script where the deletion of the record is determined by the ‘TTL’ field?

For instance a record is added at noon today, with a ‘TTL’ of 2, can I have a script that deletes that same record at noon two days from now?

What would be the best way to do this, and do I really need both fields to execute this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:20:40+00:00Added an answer on June 7, 2026 at 1:20 pm

    Your best method for running this script is attaching it to cron and having it run on a given interval.

    Then, in order to program the record deletion, you’ll need to run the following query:

    DELETE FROM records WHERE UNIX_TIMESTAMP(time_stamp) + TTL * 86400 <= CURRENT_TIMESTAMP()

    time_stamp is your record creation value – let’s say it’s equal to 1000000. 86400 is the amount of seconds in a day. TTL is the amount of days after time_stamp that you want the file deleted. So if TTL is 2 and 1000000 was the timestamp for July 10th, we are basically comparing:

    1000000 + 86400 * 2 <= CURRENT_TIMESTAMP

    Now, let’s say that today is July 12th. This means it’s 2 days (86400 * 2 seconds) after July 10th. Thus,

    CURRENT_TIMESTAMP = July 10th timestamp + 2 days worth of seconds
                      = 1000000 + 86400 * 2
    

    Which implies CURRENT_TIMESTAMP >= 1000000 + 86400 * 2 for all points in time during and after July 12th, thus deleting the record.

    This will delete the records daily for you while your server is running. Enjoy and good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL database that has a table with a field set to
I i have a SQL Server database table called tbl_faults . In that table
I have a table called Field in my SQL Server database. The table has
I have a field called IntQID, which is an id for each post that
I have one field in Database ( Sql Server DB 2000) with varchar field
I have a class with like 20 fields which get populated from SQL database
I have data in a sql database that'd I'd like to display on a
In our Oracle database we have a table called RULES, with a field called
I have a SQL 2000 server with a database (ITinventory) and a table which
I have a column in my drupal database called field_concert_published_value which is storing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.