Reputation: 5716
i have a column that is a timestamp to store a date time. so i am inputting the time() result to save the value in to that column in database.
for example, result generated by time() = 1385714063 // a timestamp
echo time() //1385714063
I am adding 1385714063 (timestamp) and saving but it automatically converts 1385714063 in to 2013-11-14 00:00:00 which i dont understand how.
why i am not allowed to store the value as a timestamp(1385714063) or why is it doing the conversion is my question.
UPDATE 1
I tried, NOW() as explained in the first answer but it doesnt help me
Upvotes: 1
Views: 1490
Reputation: 809
Datatype timestamp
in MySQL is stored internally value as four-byte integer value, but externally, you need to work with this datatype as with string. If you want to store timestamp
value as integer value in MySQL, then use datatype INT
.
Upvotes: 1
Reputation: 41
Use this
SELECT UNIX_TIMESTAMP(NOW())
But i think TIMESTAMP datatype will store in "YYYY-mm-dd h:i:s" so for the timestamp you want you can use other datatype like bigint or varchar
Upvotes: 1
Reputation: 12872
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
https://dev.mysql.com/doc/refman/5.5/en/datetime.html
You should insert your date in the format of Y-m-d H:i:s
Upvotes: 0
Reputation: 4331
Try echo date("Y-m-d H:i:s");
method to store date time .My sql Database uses formate.now()
is mysql function not php
Upvotes: 2