Home  >  Article  >  Backend Development  >  How to define membership time as seven days in php

How to define membership time as seven days in php

angryTom
angryTomOriginal
2019-10-28 13:36:002501browse

How to define membership time as seven days in php

How does php define the membership time as seven days

Sometimes our website will have a membership system, which involves There is a question about membership time and expiration time. How to implement a function to set membership to expire after 7 days? Let’s learn together.

1. First, we can get the membership start time $start_time from the database;

2. Then get the current time from time() and subtract it;

3. If the time difference is greater than 86400, it expires.

The following program simulates the membership start time.

<?php
$start_time = 1307319997;
$a= $start_time - time();
if(abs($a)>86400){
    echo "与当前时间差距在7天以上";
}else{
    echo "与当前时间差距不超过7天";
}
?>

$date = date('Y-m-d', strtotime('-7 days')); //Keep the year-month-day

echo echo date(” Y-m-d H:i:s”,strtotime(”-7 day”)); //Keep year-month-day hour: minute: second

strtotime('-7 days') What you get is the timestamp

strtotime('now')); //Get the current timestamp

time() //Get the timestamp

More PHP related knowledge , please visit PHP Chinese website!

The above is the detailed content of How to define membership time as seven days in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php settings errorNext article:php settings error