Dateadd Function
DATEADD (datepart, number, expression)
select GETDATE() as 'today',
DATEADD(D, 1, GETDATE()) as 'day_d',
DATEADD(M, 1, GETDATE())as 'month_m',
DATEADD(YEAR, 1, GETDATE())as 'year_year',
DATEADD(MI, 2, GETDATE()) as 'minite_MI'
Output
today | day_d | month_m | year_year | minite_MI |
2011-07-05 19:41:35.2 | 2011-07-06 19:41:35.2 | 2011-08-05 19:41:35.2 | 2012-07-05 19:41:35.2 | 2011-07-05 19:43:35.2 |
DATEDIFF Function
DATEDIFF (datepart, expression1, expression2)
select DATEDIFF (day,getdate(),GETDATE()+1) as 'DAY_DIFFERENCE'
Output
DAY_DIFFERENCE |
1 |
Datepart Function
DATEPART (part_of_day, expression)
SELECT DATEPART(DAY,GETDATE()) as 'DAY',DATEPART(MONTH,GETDATE()) AS 'MONTH',DATEPART(YEAR,GETDATE())AS 'YEAR'
'DAY' | 'MONTH' | 'YEAR' |
5 | 7 | 2011 |
--
--
Regards,
Basheer Ahamed
No comments:
Post a Comment