Following is the rundown of date capacities in MS SQL Server.
GETDATE()
It will restore the current date alongside time.
Syntax
Language structure for the above capacity −
GETDATE()
Example
The accompanying question will restore the current date alongside time in MS SQL Server.
Select getdate() as currentdatetime
DATEPART()
It will restore the piece of date or time.
Syntax
Punctuation for the above capacity −
DATEPART(datepart, datecolumnname)
Example
Example 1 −The accompanying inquiry will restore the piece of current date in MS SQL Server.
Select datepart(day, getdate()) as currentdate
Example 2 − The accompanying inquiry will restore the piece of current month in MS SQL Server.
Select datepart(month, getdate()) as currentmonth
DATEADD()
It will show the date and time by add or deduct date and time stretch.
Syntax
Linguistic structure for the above capacity −
DATEADD(datepart, number, datecolumnname)
Example
The accompanying inquiry will restore the following 10 days date and time from the current date and time in MS SQL Server.
Select dateadd(day, 10, getdate()) as after10daysdatetimefromcurrentdatetime
DATEDIFF()
It will show the date and time between two dates.
Syntax
Grammar for the above capacity −
DATEDIFF(datepart, startdate, enddate)
Example
The accompanying question will restore the distinction of hours between 2015-11-16 and 2015-11-11 dates in MS SQL Server.
Select datediff(hour, 2015-11-16, 2015-11-11) as
differencehoursbetween20151116and20151111
CONVERT()
It will show the date and time in various organizations.
Syntax
Linguistic structure for the above capacity −
CONVERT(datatype, expression, style)
Example
The accompanying inquiries will restore the date and time in various arrangement in MS SQL Server.
SELECT CONVERT(VARCHAR(19),GETDATE())
SELECT CONVERT(VARCHAR(10),GETDATE(),10)
SELECT CONVERT(VARCHAR(10),GETDATE(),110)