SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member doctorperl's Avatar
    Join Date
    Feb 2001
    Location
    Virginia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need help with a personal script.

    I am trying to write a Perl script that creates user sessions. I need to compared time/date session was created and current time/date. However, I am having trouble figuring out a way to compare the times. :mad: Here is part of the code.

    Code:
    			@expire_date = split ' ', $session_date;  # Splits date/time from Database so I can read time and date seperately. 
    			($db_hr,$db_min,$db_sec) = split ':', $expire_date[1]; # splits the time section from Database.
    			($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdst) = gmtime;	$hr -=4;  # Gets GTM time and converts to EST time. 
    			$current_time = sprintf("%02d:%02d:%02d GMT",$hr,$min,$sec); # Pretty print of current time
    			$expired = ($db_hr - $hr).":".($db_min - $min).":".($db_sec - $sec); #one thing I tried to compared the times. failed.
    			$newtime = $expire - $current_time; # another thing used to compared. failed
    :mad:
    I'm the Doc,
    Always have, Always will be the Doc.

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Suggestion: Use unix timestamps (the seconds since Jan 1st 1970) as your internal representation of time. Doing so makes comparisons of time easy, just subtract the tiemstamp and you've got the number of seconds that have passed (which can easily be converted into hours and minutes if necessary).


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
  •