SET time_zone = '+00:00';
CREATE TABLE timestamp_n_datetime ( id INT AUTO_INCREMENT PRIMARY KEY, ts TIMESTAMP, dt DATETIME );
INSERT INTO timestamp_n_datetime(ts,dt) VALUES(NOW(),NOW());
SELECT ts, dt FROM timestamp_n_datetime;
SET time_zone = '+03:00'; SELECT ts, dt FROM timestamp_n_datetime;
SET @dt = NOW();
SELECT @dt;
SELECT DATE(@dt);
CREATE TABLE test_dt ( id INT AUTO_INCREMENT PRIMARY KEY, created_at DATETIME ); INSERT INTO test_dt(created_at) VALUES('2015-11-05 14:29:36');
SELECT * FROM test_dt WHERE created_at = '2015-11-05';
SELECT * FROM test_dt WHERE DATE(created_at) = '2015-11-05';
SELECT TIME(@dt);
SELECT HOUR(@dt), MINUTE(@dt), SECOND(@dt), DAY(@dt), WEEK(@dt), MONTH(@dt), QUARTER(@dt), YEAR(@dt);
SELECT DATE_FORMAT(@dt, '%H:%i:%s - %W %M %Y');
SELECT @dt start, DATE_ADD(@dt, INTERVAL 1 SECOND) '1 second later', DATE_ADD(@dt, INTERVAL 1 MINUTE) '1 minute later', DATE_ADD(@dt, INTERVAL 1 HOUR) '1 hour later', DATE_ADD(@dt, INTERVAL 1 DAY) '1 day later', DATE_ADD(@dt, INTERVAL 1 WEEK) '1 week later', DATE_ADD(@dt, INTERVAL 1 MONTH) '1 month later', DATE_ADD(@dt, INTERVAL 1 YEAR) '1 year later';
SELECT @dt start, DATE_SUB(@dt, INTERVAL 1 SECOND) '1 second before', DATE_SUB(@dt, INTERVAL 1 MINUTE) '1 minute before', DATE_SUB(@dt, INTERVAL 1 HOUR) '1 hour before', DATE_SUB(@dt, INTERVAL 1 DAY) '1 day before', DATE_SUB(@dt, INTERVAL 1 WEEK) '1 week before', DATE_SUB(@dt, INTERVAL 1 MONTH) '1 month before', DATE_SUB(@dt, INTERVAL 1 YEAR) '1 year before';