Below are examples of using the DATEADD function.
For all of these examples, the parameter @Date = "2011-09-23 15:48:39.2370000".
For all of these examples, the parameter @Date = "2011-09-23 15:48:39.2370000".
Examples of Using the DATEADD Function | ||
Unit of time | Query | Result |
---|---|---|
NANOSECOND | SELECT DATEADD(NANOSECOND,150000,@Date) | 2011-09-23 15:48:39.2371500 |
MICROSECOND | SELECT DATEADD(MICROSECOND,150000,@Date) | 2011-09-23 15:48:39.3870000 |
MILLISECOND | SELECT DATEADD(MILLISECOND,1500,@Date) | 2011-09-23 15:48:39.2385000 |
SECOND | SELECT DATEADD(SECOND,1500,@Date) | 2011-09-23 16:13:39 |
MINUTE | SELECT DATEADD(MINUTE,15,@Date) | 2011-09-23 16:03:39 |
HOUR | SELECT DATEADD(HOUR,-3,@Date) | 2011-09-23 12:48:39 |
WEEKDAY | SELECT DATEADD(WEEKDAY,-2,@Date) | 2011-09-21 15:48:39 |
WEEK | SELECT DATEADD(WEEK,4,@Date) | 2011-10-21 15:48:39 |
DAY | SELECT DATEADD(DD,4,@Date) | 2011-09-27 15:48:39 |
DAYOFYEAR | SELECT DATEADD(DY,14,@Date) | 2011-10-07 15:48:39 |
MONTH | SELECT DATEADD(MM,-4,@Date) | 2011-05-23 15:48:39 |
QUARTER | SELECT DATEADD(Q,-2,@Date) | 2011-03-23 15:48:39 |
YEAR | SELECT DATEADD(YYYY,-5,@Date) | 2006-09-23 15:48:39 |
No comments:
Post a Comment