Date insertion problem in php mysql

Asked

Viewed 37 times

1

I have a table of loan with the fields loan date and dateline, I want to be able to insert the current date in the table loan date and a time limit in the table dateline adding 7 days of loan date.

  • I have a table of loan with the fields loan date and dateline, I want to be able to insert the current date in the table loan date and a time limit in the table dateline adding 7 days of loan date.

1 answer

1

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

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 are looking for a solution directly on PHP, you can use the functions date and strtotime:

$data_emprestimo = date('d/m/Y');
$data_prazo = date($data_emprestimo, strtotime("+7 days"));
  • I used this method: $empretimo->createEmp(array( 'data_emprestimo' => date('Y-m-d'), 'data_limite' => date('Y-m-d', strtotime("+7 days"), 'state' => 'active' ), "loan");

  • You did not specify in which language the solution should be (PHP or MySQL), I added another answer.

Browser other questions tagged

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