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
If I know the database is MySQL, I'll use the NOW() function like this:
INSERT INTO table_name
(id, name, created_at)
VALUES
(1, 'Gordon', NOW())
You can use now()
as well in your query, i.e. :
insert into table (time) values(now());
It will use the current timestamp.
pass like this
date('Y-m-d H:i:s','1299762201428')
Some things to clarify:
therefore the correct answer would be
$timestamp = '1299762201428';
$date = date('Y-m-d H:i:s', substr($timestamp, 0, -3));
This should do it:
$time = new DateTime;
I'm guessing that the field you are trying to save the value in is a datetime field it's not but the same seems to be true for timestamps. If so mysql expects the format to be Year-month-day Hour:minute:second. In order to save the timestamp you will have to convert the field to numeric using a query like
alter table <table_name> change <field> <field> bigint unsigned
If you are using the current time you can use now() or current_timestamp.