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 7181201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:30:27+00:00 2026-05-28T17:30:27+00:00

Ive spent 4 hours trying to write a simple insert a datetime into a

  • 0

Ive spent 4 hours trying to write a simple insert a datetime into a DB, re-read that value and see how much time elapsed. I have seen horrifying example after example in PHP (my ISP only has PHP 5.2.1) not 5.3. Well, after hours of reading.. I found a solution that makes me happy but I dont know how to get it working in the way I need it to work… the code is…

create temporary table Data
( dt DateTime );

insert Data values
    (now() - INTERVAL 23 MINUTE);

select
    TIME_FORMAT(
      TIMEDIFF(now(), dt)
     ,'%i minute(s) ago'
   )
from Data;

I’m using PREPARED statements (PS)… I don’t know how to convert that to procedural style, PS. I was thinking instead of the ? I would put now() but then I had no idea what to put in the value. I thought also… i’ll just change the DB to an INT and then just stick the PHP time() value in there and do some math on it when I read it. Thats my other option but… this will make the SQL do the “work” so… can this be converted to PS?

Thank you!

All I want to do is…

update a record with now() THEN find out how much time has elapsed since I wrote that record and delete it if enough time has passed.

A website showing the code above working is…

http://sqlize.com/r1mlXcM62V

  • 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-05-28T17:30:29+00:00Added an answer on May 28, 2026 at 5:30 pm

    It’s been a whole day of struggling to figure this all out and it looks like I did it. The weird thing is SQL is actually very easy, PHP is very easy. I am old and my brain is rusty (havnt programmed for 17+ years). I visualize how it’s supposed to work in my head and something that should take seconds takes hours to research and figure out. SO… I found a solution…

    $query = "SELECT TIMESTAMPDIFF(MINUTE, `sesstoken1created`,now()) FROM pcssecurity";
    

    except I have to change it to a DELETE statement so I was thinking…

    $query = "DELETE FROM pcssecurity WHERE TIMESTAMPDIFF(MINUTE, `sesstoken1created`,now()) > 16";
    

    That will delete all timestamps found > 16 min old. Works. I also was researching what to do if there was NO variables to bind.. would it be ok to not include a BIND variables… and appearently it works without bind variables.

    SOLUTION

    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_USER_PASSWORD, DB_NAME) or die(DB_CONNECT_ERROR .  __LINE__);
    $stmt = mysqli_stmt_init($dbc);
    
    $query = "DELETE FROM tablename WHERE TIMESTAMPDIFF(MINUTE, `datetimefieldhere`,now()) > " . SESSION_TOKEN_EXPIRES_IN_MINUTES;
    $result = mysqli_stmt_prepare($stmt, $query);
    $result = mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_affected_rows($stmt);
    
    if ($result === -1) { // some error happened
        die('CreateNewToken insert failed');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent the last three hours trying to write a string to the console?
I have an issue that I've spent hours trying to figure out, but since
I've spent hours trying to get my code to work, its a rats nest
Ok so I've spent a couple hours trying to resolve this issue and have
So yeah, like I said, I've spent a few hours trying to fix this
I have a really frustrating error that I've spent hours looking at and cannot
I've spent the last 2 hours trying to find a solution for this and
I know there are many similar questions already, but I've spent hours trying to
I'm trying to write a method that determines if an ArrayList is in ascending
First things first ive tried to fix this myself for hours and spent a

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.