Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving timestamp in mysql table using php

I have a field in a MySQL table which has a timestamp data type. I am saving data into that table. But when I pass the timestamp (1299762201428) to the record, it automatically saves the value 0000-00-00 00:00:00 into that table.

How can I store the timestamp in a MySQL table?

Here is my INSERT statement:

INSERT INTO table_name (id,d_id,l_id,connection,s_time,upload_items_count,download_items_count,t_time,status) VALUES (1,5,9,'2',1299762201428,5,10,20,'1'),        (2,5,9,'2',1299762201428,5,10,20,'1') 
like image 848
gautamlakum Avatar asked Apr 12 '11 08:04

gautamlakum


People also ask

How do I add a timestamp to a MySQL table?

You need to use ALTER command to add a created at column to an already created table in MySQL. Now implement the above syntax to add a “created at” column with type timestamp and default with CURRENT_TIMESTAMP.

How is timestamp stored in MySQL?

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME, which is stored “as is”.) By default, the current time zone for each connection is the server's time.

What is $row in PHP?

Return Value: Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result set. PHP Version: 5+


1 Answers

pass like this

date('Y-m-d H:i:s','1299762201428') 
like image 80
jimy Avatar answered Oct 23 '22 22:10

jimy