| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Best way to store timestamp Hey whats the best way to store timestamp in the database? Right now i have a field called timestamp, which is an int (11) and i get "time()" of the function performed and insert it into the database with the other information, but i am not sure if this is the right way of doing it. Thanks
__________________ |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 392
![]() ![]() ![]() | As far as i know that is the best way to store the timestamp, then you can manipulate it anyway you want when retrieving it.
__________________ -Beaver6813.com - Web Developer Extraordinaire! |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | in the TYPE column [when your adding a field] there is one called "TimeStamp" i just tried that..and if you check the "Timestamp" for the default value..it adds the date in this format : 2007-01-10 12:58:53 is it better?
__________________ |
| |
| | #4 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 392
![]() ![]() ![]() | No, just go with the PHP timestamp time(). If you're using this timestamp with PHP it is by far the best way to go as you can manipulate that timestamp once you retrieve it to whatever you want. ie. that long number could transform into 02/07/07 or even just into the time 13:21. The PHP timestamp time() is also more flexible and easier to manipulate
__________________ -Beaver6813.com - Web Developer Extraordinaire! |
| |
| | #5 (permalink) |
| NamePros Member Join Date: May 2006
Posts: 160
![]() | I would suggest using the proper MySQL timestamp but using the MySQL 'conversion' functions of UNIX_TIMESTAMP and FROM_TIMESTAMP. That way you deal with normal timestamps in PHP but by using those functions you can still store in the DB proper MySQL timestamps. |
| |
| | #6 (permalink) |
| NamePros Regular Join Date: Apr 2006
Posts: 363
![]() ![]() ![]() ![]() | I've always just used the php function time() and int 11 but I guess its up to your preference I don't believe one has a significant speed/quality over the other.
__________________ Canadian Domain Registrar Ready.ca |
| |