How do I enter information in a field of this type? The field name is duration, I would like an example ..
How do I enter information in a field of this type? The field name is duration, I would like an example ..
Two syntaxes:
INSERT INTO meubanco.minhatabela ( duracao ) VALUES ( '2016-04-29 00:00:00' )
Or
INSERT INTO meubanco.minhatabela SET duracao = '2016-04-29 00:00:00'
(I hope your field is duracao
, not duração
, to avoid problems)
The important thing is to pass the date as string , in the format ano-mes-dia hora:minuto:segundo.centesimos
Ideally you will use 4 digits for the year, and 2 for all other fields, but if you pass in another format, in most cases MySQL does a guess and rounds values or expand as needed.
Some comments:
Years with two digits has the base date in 1970. Thus, values from 00
to 69
are converted to 2000
to 2069
, and values from 70
to 99
for the range 1970
to 1999
respectively.
To insert the current time, according to the DB server, you can use CURRENT_TIMESTAMP
or NOW()
;
If your column is the first TIMESTAMP
of the table, by default MySQL inserts the current timestamp if the field is omitted, or explicitly given NULL
and column specified as NOT NULL
;
When inserting fields with the timezone of MySQL configured for something other than UTC, there is an internal conversion. So, if you insert a date and change the timezone , the date returned will be different (always relative to UTC).
More details in the manual:
Ideally an application should provide the dates for MySQL in the right format to avoid conversions, but if you need a pre-conversion for insertion, you can do this:
INSERT INTO meubanco.minhatabela ( duracao ) VALUES (
STR_TO_DATE('29/04/2016','%d/%m/%Y')
)
Similarly, to include the time:
INSERT INTO meubanco.minhatabela ( duracao ) VALUES (
STR_TO_DATE('29/04/2016 13:49:20','%d/%m/%Y h:%i:%s')
)
More details of fields and other conversion functions in the manual:
p>
This method is for database manipulation. I'm not understanding exactly what it does in the column / variable.
Used to assign the value of a column of your Select to a variable.
Note that there is a very detailed explanation in the documentation, but to understand you must be familiar with "passages by reference."
See:
%pre%All the variables passed to the second bindColumn parameter will have the previously specified column value.
In this case, when we make %code% , the variable %code% is created and passes internally to the value of that column, each time the %code% is rotated.
Note that in the third call of %code% in the example, the name of the column where you want to "bind" (reference or pointer) the value for a variable is used.
Note that the second argument of %code% is a reference, so it has the values assigned according to the %code% call.
%pre%For a better understanding, the functions that have this %code% sign in the argument require a variable, so that additional values can be returned, since %code% is returned something different.
For example, it is the %code% function, which returns a %code% . In it, you can pass two parameters by reference to know what the error or error code is.
%pre%That is:
%pre%