In general, the goal is this: It is necessary to make the placement of a post for a time (1 year), that is, after a year the post should not be displayed.

The idea was to create 2 variables in the database, 1 - the current date, 2 - the end date of the publication of the post and if the current date 1 becomes more than the date 2, then we make the post not activated.

So the problem is that I don’t understand how to work with dates in the table, what to use (datetime or timestamp) and what value to put in the database itself. Re-read a bunch of information and nothing really helped. The date of the post publication is created, but it is not recorded in the database.

$date = time(); $M = idate('m', $date); $D = idate('d', $date); $Y = idate('y', $date); $H = idate('H', $date); $i = idate('i', $date); $s = idate('s', $date); $date_end = date('Ymd H:i:s', mktime($H, $i, $s, $M, $D, $Y+1)); echo strtotime($date_end); $sql = 'UPDATE `agrousadby` SET `mai_date_end` = '.$date_end.' WHERE `id` = '.$Param['id']; mysqli_query($CONNECT, $sql); 

    2 answers 2

    And why not just store the creation time of a post in the database as a single DATETIME value (let's call it created_at for definiteness) and output only those entries that are less than a year old, eliminating old entries using the following WHERE condition

     SELECT * FROM agrousadby WHERE created_at > NOW() - INTERVAL 1 YEAR; 
    • Thanks for the idea, now I'll try to write - Vadim Moroz
    • It worked. Many thanks - Vadim Moroz

    '. $ date_end.' The date in the request must be a string

     '. "'" . $date_end. "'" . '