In my web application user should register a date and the validity period(ex.5 days). So when user logging i want to check whether his account expired. To do that i want to add validity period to the user registered date? how can i do that? Some forum says to use "mktime". But still i couldn't do that. Could you please help me?
Add some specific dates to some date
Collapse
X
-
What do you mean that you could not do that? What have you tried?
I assume you are using a database to store the user information, and as an alternative, you could let the database do the date calculations for you. If you are using MySQL, date manipulations are rather easy using mysql functions. So when a user registers, you can either insert the current date into the user information table (alternatively, you can already add 5 days when doing this insert and store the user's expiration date directly). And when the user tries to log in, you can use a query comparing the current date against the date stored in the database to see if the expiration date has been past. Using the database's date functionalities may be more intuitively easier to use (depending on the database) but you could do this either way, either in PHP or using the database. -
I have done it.
[PHP]
list($year, $month, $day) = split('[/.-]', $Valid_From);
$daystoadd="$Va lidity_Period";
$hours=$daystoa dd * 24;
$newdate=date(" Y-m-d", mktime($hours, 0, 0, $month, $day, $year));
//echo "The new date is: " . $newdate."'";
if($newdate < $today)
{
echo "expierd";
}
else
{
echo "ok";
}
[/PHP]Comment
-
-
It looks like it is solved, TheServant.
But I am really curious as to why OP does not use the (easier) MySQL routines to achieve his/her goal. A simple SQL command like DATE_ADD() or DATE_DIFF() would have done it. But who am I to guess?
RonaldComment
Comment