PHP and MySQL syntax: Difference between revisions

Jump to navigation Jump to search
Line 40: Line 40:
* 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 ==
=== Query by month ===
* mysql ex: find the records in January, 2014
* mysql ex: find the records in January, 2014<ref>[http://stackoverflow.com/questions/508791/mysql-query-group-by-day-month-year sql - MySQL Query GROUP BY day / month / year - Stack Overflow]</ref>
** SELECT * FROM table_name WHERE `time` >= '2014-01-01 00:00:00' AND `time` < '2014-02-01'
** 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'
** SELECT * FROM table_name WHERE YEAR(`time`) = '2014' AND MONTH(`time`) = '1'

Navigation menu