Insert date and time into mysql automatically?

Asked

Viewed 7,815 times

2

inserir a descrição da imagem aqui

I am creating a system and I would like to know type fill the form below and how to insert in mysql the time and date as it is in the operating system . without having to input a date and time into the form .

1 answer

7


Just create a table with the date field of type TIMESTAMPand with the pre-defined value as CURRENT_TIMESTAMP

Follow Example sql:

CREATE TABLE `tabelateste` (
  `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
)

This way, whenever you enter a record, you do not need to inform the date, and it will be inserted with the server system date

  • You could do me a favor, you have that data from the above forms, type, number of the command, on one of the table , request for food and drink and quantities, could you show me how to create the table together with the date and time ? would be grateful @localhost

  • yes , with the shaman

  • well the name of the database is fishmongery , the data to be entered are those of the image above , type , number of the command , will come automatically every time I open a new form. has the table number, meal and quantity, drink and quantity.

  • I recommend Create an ordered table with {id_request,numero_command, numero_table} and another item_request{id_item table, id_order, order, quantity} . This would be the simplest way, where the requested id_and always informed on each item that will be informed in the item_request table

  • then it will be these two new and the date and time table is

  • @allanaraujo the table that has the date would be on request , it would be a request with the information of the same, ai na outra armazria os itens desse pedido

  • It was like this CREATE TABLE peixaria.item_pedido ( id_item INT NOT NULL , id_pedido VARCHAR(255) NOT NULL , pedido VARCHAR(255) NOT NULL , quantidad VARCHAR(255) NOT NULL , data TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , algo VARCHAR(255) NOT NULL , PRIMARY KEY (id_item)) ENGINE = Myisam CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; is correct ?

  • @allanaraujo believe so, but the amount could be int or double

Show 3 more comments

Browser other questions tagged

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