Date expiring from date of registration (datetime) - MYSQL

Asked

Viewed 114 times

0

The field is of type datetime, how to display the date for 30 days from the registered date, example:

<?php

// `data_cad` = '2018-03-01 01:52:00'

$instrucao = "SELECT 
                `user_id`,
                `status`,
                `user_nome`,
                `data_cad` 
              FROM 
                `usuario` 
              ORDER BY 
                `user_nome` 
                  ASC 
              LIMIT 1";

$query = mysqli_query($conn, $instrucao);

$arr = mysqli_fetch_array($query);

?>

If the registration date is 01/03/2018 ('2018-03-01 01:52:00'), the expiration date will be 31/03/2018. But how to count the date making mysql understand that the year has only 28 days in February, 31 days in March, finally, the date needs registration to expire 30 days from now.

Thank you.

1 answer

1

I resolved making use of DATE_ADD with INTERVAL X DAY

"SELECT DATE_ADD('2018-12-20 01:52:00', INTERVAL 30 DAY);"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.