Jump to content

date()


Matpatnik
 Share

Recommended Posts

Hi guys, is there a function to get the date in number eg: the number of day since the begaining of php, my db or the world...What I'm trying to do is restric access to someone after so many days. So I'm wonderring if something already exist for that or do I have to create it. I've looked on php.net but I didn't find anything.Thank you for your helpMatpatnik

Link to comment
Share on other sites

The time function will return the number of seconds since 1/1/70, which is referred to as the Unix epoch timestamp. From there you can add or subtract however many seconds you want. One day contains 86,400 seconds, so adding 86400 to the timestamp would be the same time tomorrow. I use Unix timestamps whenever I work with dates, I just find the simple addition and subtraction of seconds more logical then working with a full blown date object.http://www.php.net/manual/en/function.time.phpThere is also a microtime function to return the number of microseconds instead of seconds if you need more precision, and you can use the timestamp with functions like date and getdate to get the specifics about the date, like month, day, hour etc, and you can use the mktime function to make a timestamp based on a certain date and time.

Link to comment
Share on other sites

if you're restricting access to someone after a sort of trial period, then when the user adds to the database you also insert a timestamp of the time they do so into the db. Then, in your PHP you do something like (assuming the column where the timestamp is located is called user_trial_begins):

 //Assuming you've gotten user data already in a variable named $user; if($user['user_trial_begins']+(60*60*24*7)>=time()){   echo "Trial expired!";    die();}//Execute other code normally

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...