SELECT command with SQL DATE method:

There is lots of date method which are widely used in SQL server database in which some are given as follows.

SELECT command with GETDATE () function:

GETDATE () method returns current system date.

Syntax:

SELECT GETDATE ()

Example:
--- RETURN CURRENT SYSTEM DATE
SELECT GETDATE() AS TODAY_DATE


‘SELECT’ Command with Date Method

SELECT command with DATEADD () function:

Returns new date time value by adding an interval of date time.

Syntax:

SELECT DATEADD ([MONTH |YEAR |DAY], [NUMBER], DATETIME)

 Example:
---- DATE ADDED AFTER AN INTERVAL
SELECT DATEADD(MONTH,6,GETDATE()) AS INCREMENTED_DATE


‘SELECT’ Command with Date Method

SELECT command with DATENAME () function:

Returns a character string that represent specified date part.

Syntax:

SELECT DATENAME ([DATEPART], [STARTDATE])

Example:
---- RETURNS DATENAME EITHER DAY NAME, YEAR NAME OR MONTH NAME
SELECT DATENAME(DAY,GETDATE()) as DAY_STRING


‘SELECT’ Command with Date Method

SELECT command with DATEDIFF () function:

DATEDIFF () method returns date difference between two date.

Syntax:

SELECT DATEDIFF ([DATEPART], [STARTINGDATE], [ENDDATE])

Example:
---- RETURNS DIFFERENCE BETWEEN TWO DATE 
SELECT DATEDIFF(YEAR,GETDATE(),DATEADD(MONTH,6,GETDATE()))


‘SELECT’ Command with Date Method

SELECT command with DATEPART () function:

DATEPART () function returns the part of date such as year, day, month etc.

Syntax: 

SELECT DATEPART ([date part], [date])

Example:
---- RETURNS DATE PART OF GIVEN DATE 
SELECT DATEPART(YEAR,GETDATE())


‘SELECT’ Command with Date Method

SELECT command with DATELENGHT () function:

DATELENGTH () returns the length of given date.

Syntax:

SELECT DATELENGHT ([given date])

Example:
--- RETURNS DATE LENGTH OF GIVEN DATE
SELECT DATALENGTH(GETDATE())


‘SELECT’ Command with Date Method


  Modified On Mar-22-2018 05:57:40 AM

Leave Comment