Question

How can I alter a Mysql table time stamp to such as the following:

dd/mm/yy 00:00:00

I tried:

ALTER TABLE TbMessage MODIFY startdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

But is not the formate as i thought:

0000-00-00 00:00:00

can some one help me? Because the date which i am receiving for the table is in the format DD/MM/YYYY from a SQL Database. I cant chnage the formate in the database of SQL.

Était-ce utile?

La solution

A timestamp/datetime is always stored the same way in the database. It is the representation in your selects that you can influence.

For that you can use DATE_FORMAT. Example:

select date_format(datetime_column, '%d/%m/%Y %k:%i:%s') 
from your_table

And if you want to store date and time you should rather use the datetime data type. So I recommend to use

ALTER TABLE TbMessage 
MODIFY `startdate` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top