1

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

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

it says, Call to undefined function now()
Sorry check answer now
1

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

Comments

1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.