DATABASE & SQL/PLSQL

adplus-dvertising
Date Functions in SQL
Previous Home Next

Features of date functions area

  1. Used to manipulate date time values
  2. Perform arithmetic operations
  3. Perform date parsing
  4. Add two date or subtract one date from another

SELECT date_function (parameters)

date_function is the name of date function

parameters are the required parameters of the date function

Eunction NameParameterDescription
DATEADD (datepart,number,date) Adds the number of dateparts to the date
DATEDIFF (datepart,date1,date2)<\i> Calculates the number of dateparts between two dates
DATENAME (datepart,date)<\i> Return datepart from the listed date, as character value (for example: March)
DATEPART (datepart,date)<\i> Returns datepart from the listed date as an integer
GETDATE ()<\i> Returns current date and time

Example

SELECT getdate()

The above statement display the current system date by using getdate() function.

SELECT  'getdate'= DATEADD(yy,2,pubdate)
FROM titles

output

Return the all pubdate from titles table with increment of 2 in each year of the table.

SELECT datepart (yy,pubdate)
FROM titles

Return all Date from pubdate of titles table.

Previous Home Next