Wednesday, March 11, 2009

Date and Time Operation mysql

mysql> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY);
        -> '2009-02-02'
mysql> SELECT ADDDATE('2009-01-02', INTERVAL 31 DAY);
        -> '2009-02-02'

mysql> SELECT ADDTIME('2007-12-31 23:59:59.999999', '1 1:1:1.000002');
        -> '2009-01-02 01:01:01.000001'
mysql> SELECT ADDTIME('01:00:00.999999', '02:00:00.999998');
        -> '03:00:01.999997'


mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
        -> '2004-01-01 13:00:00'
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
        -> '2004-01-01 22:00:00'

mysql> SELECT CURDATE();
        -> '2009-06-13'
mysql> SELECT CURDATE() + 0;
        -> 20090613

mysql> SELECT CURTIME();
        -> '23:50:26'
mysql> SELECT CURTIME() + 0;
        -> 235026.000000
mysql> SELECT DATE('2005-12-31 01:02:03');
        -> '2005-12-31'

mysql> SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
        -> 1
mysql> SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');

No comments: