Matpatnik Posted September 18, 2007 Share Posted September 18, 2007 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 More sharing options...
justsomeguy Posted September 18, 2007 Share Posted September 18, 2007 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 More sharing options...
Matpatnik Posted September 18, 2007 Author Share Posted September 18, 2007 Nice,so if I write something like that: <?php$tm7=time() + (86400*7);if ($time <= $tm7) { return true;} else { return false;}?> $time is true until 7th days then it come false? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2007 Share Posted September 18, 2007 Right, assuming $time was created when $tm7 was created. Or you can do this: if (time() - (86400 * 7) < $time) //$time is more then a week ago Link to comment Share on other sites More sharing options...
Matpatnik Posted September 18, 2007 Author Share Posted September 18, 2007 Thank you you saved me a lot of coding Link to comment Share on other sites More sharing options...
jhecht Posted September 19, 2007 Share Posted September 19, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.