Problem with date insertion in php mysql

1

I have a table of loans with the fields data_emprestimo and data_prazo , I want to be able to insert the current date in the and a deadline in the data_prazo table by adding 7 days of data_emprestimo .

    
asked by anonymous 08.03.2017 / 14:48

1 answer

1

You can use the following functions NOW() and DATE_ADD() , combining -as you would:

SELECT

SELECT NOW() AS data_emprestimo, DATE_ADD(NOW(), INTERVAL 7 DAY) AS data_prazo;

INSERT

INSERT INTO emprestimos (data_emprestimo, data_prazo) VALUES (NOW(), DATE_ADD(NOW(), INTERVAL 7 DAY))

@edit

If you search for a solution directly in PHP , you can use date functions and strtotime :

$data_emprestimo = date('d/m/Y');
$data_prazo = date($data_emprestimo, strtotime("+7 days"));
    
08.03.2017 / 18:00