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
⇒ DATEDIFF() - Calculating DATETIME Value Differences in SQL Server
⇐ Incrementing or Decrementing Parts of DATETIME Values in SQL Server
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-20, 4240🔥, 0💬
Popular Posts:
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How To Create a Dynamic Cursor with the DYNAMIC Option in SQL Server Transact-SQL? If the underlying...
What are single-byte character string data types supported in SQL Server Transact-SQL? Single-byte c...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...