How to save date in mysql table

Asked

Viewed 61 times

0

I am trying to insert the current date into a table, I am using the following code:

insert into testar (data,nome) VALUES (date("Y-m-d H:i:s"),'pedro');

yet of error:

Column 'data' cannot be null.

3 answers

1

Make use of CURRENT_TIMESTAMP

INSERT INTO testar (data,nome) VALUES (CURRENT_TIMESTAMP,'pedro')
  • Worked thanks.

  • @Read this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

0

Use the NOW() to place the current date.

INSERT INTO testar 
(data, nome)
VALUES 
(NOW(), 'Pedro')

0

You can use the NOW() command for this would look like this:

insert into testar (data,nome) VALUES (NOW(),'pedro');

Browser other questions tagged

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