By 25/02/2016 1 Comments

What Are Date Functions In SQL Server?

  • There are some special built-in functions in SQL Server for handling the date and time in database.
  • These SQL Server functions define different operations for date and time.
  • The date data types of a table column can be set at the time of table creation in database.

Following Date Functions are available in SQL Server:

Function Description
GETDATE() Represent current date and time
DATEPART() Represent a single part of a date/time
DATEADD() Adds or subtracts a specified time interval from a date
DATEDIFF() Represent the time between two dates
CONVERT() Returns date/time data in different formats


Date or time values can be inserted in SQL Server database by using the following date data types:

Data type Accept format
DATE YYYY-MM-DD
DATETIME YYYY-MM-DD HH:MI:SS
TIMESTAMP Can be a unique number
SMALLDATETIME YYYY-MM-DD HH:MI:SS

Example

SELECT p_name, price, p_date
FROM products
WHERE p_date = '2015-01-20';


Note:

  • In above example the SELECT statement selects only a product which is added on 2015-01-20.





Next Tutorial →


← Previous Tutorial


Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .