SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: little help in Time Difference!!
-
Mar 9, 2006, 12:38 #1
- Join Date
- Dec 2005
- Posts
- 55
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
little help in Time Difference!!
Hi,
When user visits the site his visit_time and visit_date is stored in the database, What I want is to delete the visitor details after completetion of 24 hours.. for example..
if user visit_time=23:00 and visit_date=9 March 2006
then the record will be deleted when
date=10 March 2006 and time=23:00 (24 hours completed)
This will be done via cron job (which will run every day at mid night)
Thanx for help in advance....
-
Mar 9, 2006, 14:01 #2
- Join Date
- Jul 2002
- Location
- Along the Wasatch Fault line.
- Posts
- 1,771
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So, what is the question?
John
-
Mar 9, 2006, 14:05 #3
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
also, is visit_time stored as a timestamp? or as a string representation of a date?
hope its a timestamp, will make things much easier.
-
Mar 9, 2006, 14:45 #4
- Join Date
- Dec 2005
- Posts
- 55
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
At the moment i have time formats in string... here is the code
Code:<?php //get current server time require_once("db.php"); $current_time = date("H:i:s"); $current_date = date("j F Y"); $ip=$_SERVER['REMOTE_ADDR']; $q="DELETE from visitor where '$current_date'>visit_date" AND what codtion to put here for time(24 hours); $result = mysql_query($q,$status)or die("no match found")
-
Mar 9, 2006, 14:55 #5
- Join Date
- Jul 2002
- Location
- Along the Wasatch Fault line.
- Posts
- 1,771
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is it too late to change the times you have in the database to a timestamp? As ClamCrusher has said, it's easier to work with timestamps, as you can test in this manner:
is the current timestamp 86400 or more greater than the timestamp in the database
if($databaseTimestamp + 86400 < $currentTimestamp)
{
delete
}John
-
Mar 9, 2006, 14:59 #6
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yeah if you had timestamps in your db you could just do the update in a single sql statement
since its in string format, your going to need to loop through your records 1 by 1, take the date string, convert it to a timestamp, then you can:
if($databaseTimestamp + 86400 < $currentTimestamp)
{
delete
}
fortunately, strtotime() will probably make short work of converting your strings to timestamps.
its a very good practice to store dates as timestamps.
-
Mar 9, 2006, 15:11 #7
- Join Date
- Dec 2005
- Posts
- 55
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok one little question regarding that condition
Code:if($databaseTimestamp + 86400 < $currentTimestamp) { delete } why we add 86400 here? thanx
-
Mar 9, 2006, 15:26 #8
- Join Date
- Jul 2002
- Location
- Along the Wasatch Fault line.
- Posts
- 1,771
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Timestamps are recorded in seconds. 86400 is the number of seconds in 24 hours.
John
-
Mar 9, 2006, 15:33 #9
- Join Date
- Dec 2005
- Posts
- 55
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Okies ...
thanx for your help friends...
Bookmarks