Gossamer Forum
Home : General : Perl Programming :

Need help ith date and time!! DESPARATE!

Quote Reply
Need help ith date and time!! DESPARATE!
Can someone, pleaes, give me an example of the code, that would compare the dates, and if date of last visit is one hour less then the date of this visit, the script would print "One hour has passed!";. Otherwise, it would print "Not yet. Please wait a bit more.". I really need this!
Your help would be greately appreciated!
Thanks.
Quote Reply
Re: Need help ith date and time!! DESPARATE! In reply to
Code:
$time_pass = time() - 3600;

$time_pass >= $stored_time ? ($message = "One hour has passed!") : ($message = "Not yet. Please wait a bit more.");

$stored_time would be the time that they last visited, which should be stored somewhere in epoch time. You can do this using time().


------------------
Chris

[This message has been edited by Chris071371 (edited January 11, 2000).]
Quote Reply
Re: Need help ith date and time!! DESPARATE! In reply to
So, you read the time using time(); command. Then divide by 3600, since that's the number of seconds in hour - right?
Can I store the last time in a file?
like, lasttime.file?
Quote Reply
Re: Need help ith date and time!! DESPARATE! In reply to
Well, you've almost got the idea.

time() is the time passed since January 1, 1970 in seconds. When we call time, it will give us a long number that represents this time. When your visitor first visits the site, (they need to either have a username or you will have to set a cookie to identify each user) you will either set a cookie or write their username to a file on the server along with the value of time. The value will be something like 946080000. Now, with the code I posted above, $time_pass is the current time minus 1 hour (3600 seconds). So, if the current time minus 1 hour is greater than or equal to the time written to the cookie or the file, you get the "One hour has passed" message.



------------------
Chris
Quote Reply
Re: Need help ith date and time!! DESPARATE! In reply to
So, if I want to chekcfor one day, i'd do 60*60*24?
Ok.
THANKS A MIL! Smile