SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    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....

  2. #2
    if($awake){code();} PHP John's Avatar
    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

  3. #3
    SitePoint Wizard silver trophy
    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.

  4. #4
    SitePoint Enthusiast
    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")

  5. #5
    if($awake){code();} PHP John's Avatar
    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

  6. #6
    SitePoint Wizard silver trophy
    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.

  7. #7
    SitePoint Enthusiast
    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

  8. #8
    if($awake){code();} PHP John's Avatar
    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

  9. #9
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okies ...
    thanx for your help friends...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •