Tuesday, 6 May 2014

MySQL Function : DATE_ADD()

MySQL Function : DATE_ADD()

Definition:
Get date for specific time interval.

Syntax:
DATE_ADD(date, INTERVAL expr type)

Example - 01:
SET @ExampleDate = '2014-01-01';
SELECT DATE_ADD(@ExampleDate, INTERVAL 20 DAY) AS 'Add20Days';

Output:   2014-01-21

Example - 02:
SET @ExampleDate = '2014-01-01';
SELECT DATE_ADD(@ExampleDate, INTERVAL 6 WEEK);

Output:   2014-02-12

Important Notes:
Type Value :
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR 
YEAR_MONTH

0 comments:

Post a Comment