minte9
LearnRemember / MYSQL



Extract

Extracts parts from the date.
 
SELECT EXTRACT(YEAR FROM '2009-07-02');

       -> 2009

Date add / Add

Add days (months, years) to a date.
 
SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY);

        -> 2008-02-02

SELECT ADDDATE('2008-01-02', 31);

        -> 2008-02-02

Days difference / Difference

Returns the difference in days from one date to the other. Only the date parts of the values are used in the calculation.
 
SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');

        -> 1






Questions and answers




Add days to day

  • a) SELECT {{ADDDATE}}('2008-01-02', INTERVAL 31 DAY);
  • b) SELECT {{DATEDIFF}}('2008-01-02', INTERVAL 31 DAY);


References