PHP: Time(Solved)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

PHP: Time(Solved)

Post by raghavan20 »

I have got a table ChatMessages_tbl with a field 'Time' in Mysql which is of datatype timestamp(14).

The values are inserted using "insert(NOW())"

Now, I want to delete entries in ChatMessages_tbl which are more than half an hour old from the current time.

I am looking for the syntax.

I tried this, but deletes even recent messages.

Code: Select all

$oldTime = date("YmdHis",time()) - (60*30);
$query = "delete from ChatMessages_tbl where `Time` < $oldTime";
Last edited by raghavan20 on Wed Aug 10, 2005 11:04 am, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Try something like this:

Code: Select all

$query = "delete from ChatMessages_tbl where 
DATEDIFF(Time, now()) > 30";
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

This is wot it came up with
Error

SQL-query :

DELETE FROM `ChatMessages_tbl` WHERE DATEDIFF(

`Time` ,
NOW( )
) > 30

MySQL said:


#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( `Time` ,
NOW( ) ) > 30' at line 1
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I have found this query which works:

Code: Select all

delete from `ChatMessages_tbl` where (TIME_TO_SEC(NOW()) - TIME_TO_SEC(`Time`)) > (60*30)
Post Reply