Re: Converting integers to datetime
Peter schrieb:
> I have the following fields in a database:
>
> year integer(4) not null default '0'
> month integer(2) not null default '0'
> day integer(2) not null default '0'
> hour integer(2) not null default '0'
> minute integer(2) not null default '0'
>
> and just added (using alter table) the following blank field:
>
> date datetime not null default '0'
>
> I want to use (year, month, day, hour, minute) to fill in the datetime field
> using the MySQL monitor. How can this be done?
>
By using the appropriate UPDATE statement, I'd guess. Like so (untested)
UPDATE table
SET date <----------- bad, bad choice for a name.
= concat(year,'-',month,'-',day,' ',hour,':',second)
You might want to read the documentation concerning the use of
reserved names, the date-time and string functions, and the format for
date/time literals. The documentation is available at dev.mysql.com/doc
|