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…
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…
except I have to change it to a DELETE statement so I was thinking…
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