Collections:
DATEADD() Function Usage Examples in SQL Server
How To Use DATEADD() Function in SQL Server Transact-SQL?
✍: FYIcenter.com
DATEADD() is a very useful function for manipulating date and time values. The following tutorial exercise shows you some good DATEADD() usage examples:
-- Incrementing 1 year on a leap date DECLARE @birth_date DATETIME; SET @birth_date = '2000-02-29 16:00:00.000'; SET @birth_date = DATEADD(year, 1, @birth_date); SELECT @birth_date; GO 2001-02-28 16:00:00.000 -- Decrementing 1 month on a leap date DECLARE @birth_date DATETIME; SET @birth_date = '2000-02-29 16:00:00.000'; SET @birth_date = DATEADD(month, -1, @birth_date); SELECT @birth_date; GO 2000-01-29 16:00:00.000 -- Incrementing 2 milliseconds DECLARE @birth_date DATETIME; SET @birth_date = '2000-02-29 16:00:00.000'; SET @birth_date = DATEADD(millisecond, 2, @birth_date); SELECT @birth_date; GO 2000-02-29 16:00:00.003
⇒Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-20, 2352👍, 0💬
Popular Posts:
How to run Queries with SQL Server Management Studio Express in SQL Server? 1. Launch and connect SQ...
How To Define an External Table in a Text File in Oracle? You can use the CREATE TABLE statement to ...
How To Change the Name of a Database User in SQL Server? If you want to change the name of an existi...
How to create new tables with "CREATE TABLE" statements in SQL Server? If you want to create a new t...
Where to find answers to frequently asked questions on Storage Engines: MyISAM, InnoDB and BDB in My...