Very short trick: adjust the dates by MySQL

. Sometimes you find it impossible to change the time setting up a Web Server or MySQL to work on a table where a field TIMESTAMP is set to ON UPDATE CURRENT_TIMESTAMP . So it becomes necessary, in the face of a select, adjust the time retrieved with the correct time zone. For example, if our server is located in Los Angeles, with a time zone 9 hours back, simply use:

1
2
campo_timestamp , INTERVAL 9 HOUR ) AS `local_timestamp` SELECT DATE_ADD (campo_timestamp, INTERVAL HOUR 9) `AS` local_timestamp
FROM mytable

è la stessa data 9 ore avanti. The field campo_timestamp contains the actual date of the server and the alias local_timestamp is the same on 9 hours ahead.

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL