PHP and MySQL syntax: Difference between revisions

Jump to navigation Jump to search
Line 1: Line 1:
mulitple approaches to completing the same/similar task using PHP and MySQL syntax
mulitple approaches to completing the same/similar task using PHP and MySQL syntax


== timestamp ==
== time / timestamp ==
Convert time stamp <--> the human readable time format
Convert time stamp <--> the human readable time format
=== now ===
=== now ===
Line 39: Line 39:
* php: using mktime() function
* php: using mktime() function
* mysql: SELECT TIMEDIFF('2010:01:01 00:00:00', '2010:02:01 00:00:00'); /* return -744:00:00 */
* mysql: SELECT TIMEDIFF('2010:01:01 00:00:00', '2010:02:01 00:00:00'); /* return -744:00:00 */
=== Query by month ==
* mysql ex: find the records in January, 2014
** SELECT * FROM table_name WHERE `time` >= '2014-01-01 00:00:00' AND `time` < '2014-02-01'
** SELECT * FROM table_name WHERE YEAR(`time`) = '2014' AND MONTH(`time`) = '1'


=== further reading ===
=== further reading ===

Navigation menu