0

The input e.g 1327500671 is acquired during post method. I would like to save it into the database date column defined as "registerDate Date".

I couldn't find what date/time function can do this. I can fix the Date type in DB back into varchar, which makes things easier but I still would like to learn what type of format is most used to save datetimestamp into the database in more realife applications, as I am thinking they won't save it as 1/25/2012 21:49:00, for example.

1 Answer 1

2

May I suggest storing the timestamps in the database and using the PHP date() function to make them human readable as and when necessary:

$timeStamp = 1327500671 //a timestamp from the database
$registerDate = date("j-m-y H:i:s", $timeStamp)
Sign up to request clarification or add additional context in comments.

4 Comments

:D Thanks but could you tell me why the timestamps ?
They are easier to work with than formatted dates. For example, if you want to know the date one day after, simply add 86400 to the timestamp, then convert to a human readable date.
I agree with Isiscode. You can also convert a timestamp to a time depending on the timezone you are located. For example the same timestamp means a different time UTC and a different in another location.
You can also do these things with a MySQL datetime column and the date functions in PHP and MySQL. Definitely consider storing the datetime in UTC.

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.