Thursday, November 7, 2024

Date Functions in SQL


Select Getdate() as CurrentDate;

Select Getdate() -1 PreviousDate;

Select Getdate() +1 NextDate;

Select DATEADD(dd,1,getdate()) as NextDate;

Select DATEADD(mm,1,getdate()) as NextMonth;

Select DATEADD(yy,1,getdate()) as NextYear;

Select MONTH(getdate()) as CurrentMonth;

Select EOMONTH(getdate()) as MonthEndDate;

Select EOMONTH(getdate(),1) as NextMonthEndDate;

Select YEAR(getdate()) as CurrentYear

Select DATEDIFF(dd,getdate(),eomonth(getdate())) as NoOfDaysLeftThisMonth;

Select DATEPART(year, CURRENT_TIMESTAMP) as ExtractingYear;

Select DATEPART(year, getdate()) as ExtractingYear;

No comments:

Post a Comment

Date Functions in SQL

Select Getdate() as CurrentDate; Select Getdate() -1 PreviousDate; Select Getdate() +1 NextDate; Select DATEADD(dd,1,getdate()) as NextDate;...