Saturday, June 9, 2012

Date functions available in sql server

Day(getdate())-- Get the current day
Month(Getdate())--Get the current month.
Year(Getdaet())-- Gets the current year

Datepart(interval,date)

Intervals are "yy,  mm, dd, hh,  m1, ss, dw(Day of week).

select datepart(dw,Getdate()) output is "1"

select datename(dw, Getdate()) output is "monday"

DataAdd() function
Used to add years or months to particular date.

DateAdd(yy,1,getdate()) --It adds 1 year to current year.

DateDiff(interval,date1,date2): returns difference between 2 dates.
datediff(yy,getdate(),'11-feb-2012');

No comments:

Post a Comment