Bulbul Anwar
Bulbul Anwar

Reputation: 51

date shown in database as 0000-00-00

Date shown in mysql database as 0000-00-00 when the data type is 'date', but when the data type is 'varchar(160)', it shown as 1454803200, now how I can get the correct date format as 'Monday 01 Feb 2016'? Here I have used php code 'INSERT INTO' to write into the table of the database.

Upvotes: 1

Views: 741

Answers (1)

Devon Bessemer
Devon Bessemer

Reputation: 35347

1454803200 looks to be a unix timestamp. You can use MySQL functions to convert it or PHP functions to convert it if you want it in MySQL date format which is YYYY-MM-DD.

PHP date can convert it using the second argument of the function:

$date = date('Y-m-d', 1454803200);

Within MySQL, you can use FROM_UNIXTIME() to convert it to a date format:

FROM_UNIXTIME(1454803200)

Upvotes: 2

Related Questions