In this article, I would like to show the utility of Getdate functions in SQL Server. So let's have a look at a practical example of how to use the getdate function with a different query to find the date and time in SQL Server 2012. The example is developed in SQL Server 2012 using SQL Server Management Studio.
Getdate Function
The GETDATE() function returns the current date and time from the SQL Server.
SELECT GETDATE() AS [DateTime]
Output

Curent Date Without Time
The query below returns the date without time.
Declare @date datetime
set @date=DATEADD(DAY, DATEDIFF(day, 0, getdate()), 0)
select @date
Output

Tomorrow's Date Without Time
The query below returns Tomorrow's date without time.
Declare @date date
set @date=DATEADD(DAY, DATEDIFF(day, 0, getdate()), 1)
select @date
Output

Start Date of Last Month
The query below returns the start date of the previous month.
DECLARE @StartDateofLastMonth DATETIME
SET @StartDateofLastMonth = DATEADD(mm, DATEDIFF(mm, 0, getdate()) - 1, 0)
select @StartDateofLastMonth
Output

End Date of Last Month
The query below returns the end date of the previous month.
DECLARE @StartDateofLastMonth DATETIME, @EndDateofLastMonth DATETIME
SET @StartDateofLastMonth = DATEADD(mm, DATEDIFF(mm, 0, getdate()) - 1, 0)
SET @EndDateofLastMonth = dateadd(dd, -1, DATEADD(mm, 1, @StartDateofLastMonth))
select @EndDateofLastMonth

Start Date of Current Month
The query below returns the start date of the current month.
DECLARE @StartDateofLastMonth DATETIME
SET @StartDateofLastMonth = DATEADD(month, datediff(month, 0, getdate()), 0)
Output


Rohatash KumarPosted Mar 18, 2013, 3:41 AM
Deepak. I have already written a article about the Functionality of Full_Text_Search. See it. http://www.c-sharpcorner.com/UploadFile/rohatash/full-text-indexing-in-sql-server-2012/
Deepak DwijPosted Mar 16, 2013, 11:13 AM
Good Article for beginners. Can i know about the Functionality of Full_Text_Search feature of SQL SERVER.
Liu PenghaoPosted Mar 6, 2013, 10:32 PM
learn something