php already uses the server's date.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
likewise sql now()
is equivalent to php time()
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
That is because your column type is set to datetime or timestamp not certain which one actually produces that as I don't use the mysql datetime or timestamp data type.
To store a unix timestamp you just need an INT(10)
It really is best to store a mysql timestamp, or datetime as mentioned:
In your mysql table you should set the type to 'timestamp' and then set the default to 'CURRENT TIMESTAMP'.
It doesnt really need to be explained. All that is doing is getting the date and time from the server and sticking it in a field. Just remember not to update it when you update the table, that way it will stay the day the user registrated.
Hope this helps, if you need anything else or i've miss understood dont hesitate to ask.
Also, if you need more info on timestamp and storing the date, i suggest you consult the manual. It contains some really usefull stuff.
So just create a column of type timestamp. And set the default to 'CURRENT TIMESTAMP'. Can't be any more simple.
This will default to the mysql timezone, however you can change this per connection or globally. http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
When you retrieve the date, you can format it directly on mysql or pass it to PHP to do the formatting.
To format it in MySQL:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
To use PHP to format, first convert it to a UNIX_TIMESTAMP.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp
ie:
"SELECT *, UNIX_TIMESTAMP(Registration_date) AS timestamp FROM your_db_table_name LIMIT 1"
You can then use PHP's date formatting functions to format the timestamp.
Using this method provides more portability of the database data, as well as reduces errors with timezones.
The main reason to use mysqls built is dates is that you can query based on the dates, which are indexed, and thus very fast as well as use the mysql date functions in your queries.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101