MyBB Community Forums

Full Version: Date and time in mysql
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can someone help me with this:

I am coding a bookmark feature for my website. And i want when someone bookmarks something to add the date to the mysql field.

I want to add the date and time like this: Dec 24, 2010, 10am or pm

However i do not know what the field type in mysql should be and what the php function date should look like
You can use mktime() function for this. Try reading this too: http://php.net/manual/en/function.mktime.php
This is what php offers and is what i need: date("F j, Y, g:i a"); that still leaves the question what should the field in my table be:
date, datetime, time, timestamp?
What you should do instead is store your date as a proper UNIX timestamp in the database. No timezone errors that way. Then you can render it as a formatted date via php for reading. That's how MyBB does it. Storing a date string, vs. a UNIX timestamp can lead to everything being off if you switch servers, if the time is determined by the client's timezone setting, etc...