Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
-- two days from now
SELECT GETDATE() + 2
-- 15 hours, 23 minutes and 4 seconds ago:
SELECT GETDATE() - (15*3600+23*60+4)/86400.
SELECT GETDATE() - '15:23:04'
-- somewhere in 22nd century....
SELECT GETDATE() + GETDATE()
-- somewhere in early 20th century...
SET DATEFORMAT DMY
SELECT GETDATE() - '20/05/2005'
DECLARE @dob1 smalldatetime; SET @dob1 = '19730105'
DECLARE @dob2 smalldatetime; SET @dob2 = '19791125'
-- on this date, 2nd person will be as much as old as 1st person now:
SELECT GETDATE() - @dob1 + @dob2
SELECT DATEDIFF(hh, @date1, @date2)
SET DATEFORMAT DMY
SELECT DATEDIFF( hh, '20/05/2005 13:00:00', '20/05/2005 14:00:00' )
SELECT DATEDIFF( hh, '20/05/2005 13:59:59', '20/05/2005 14:00:00' )
SELECT DATEDIFF( hh, '20/05/2005 13:00:00', '20/05/2005 14:59:59' )
SELECT DATEDIFF(ss, @date1, @date2)/3600
SELECT DATEDIFF( hh, 0, @date2-@date1 )
... WHERE dateColumn BETWEEN @dateFrom and @dateTo
... WHERE dateColumn [b]>=[/b] @dateFrom AND dateColumn [b]<[/b] @dateTo [b]+ 1[/b]
-- from UNIX to SQL2k
SELECT DATEADD(ss, <UNIXvalue>, '1970')
-- from SQL2k to UNIX
SELECT DATEDIFF(ss, '1970', <SQL2kValue> )
SELECT DATEADD(<datepart>, DATEDIFF(<datepart>, 0, GETDATE()), 0)
SELECT DATEADD(mm, 1 + DATEDIFF(mm, 0, GETDATE()), 0) - 1
SELECT CONVERT(smalldatetime, CONVERT(varchar(8), GETDATE(), 112))
SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)
-- to hh:mm:ss
SELECT CONVERT(varchar(8), GETDATE(), 108)
-- to number of seconds
SELECT DATEDIFF(ss, 0, CONVERT(varchar(8), GETDATE(), 108))
-- with date string. Format is forced (120) to prevent internationalization issues
SELECT CONVERT(smalldatetime, CONVERT(varchar(4), @y) + '-' + CONVERT(varchar(2), @m) + '-' + CONVERT(varchar(2), @d), 120)
-- with pure date arithmetics:
SELECT DATEADD(dd, @d-1, DATEADD(mm, @m-1, DATEADD(yy, @y-1900, 0)))
DECLARE @dob smalldatetime; SET @dob = '19730105'
DECLARE @today smalldatetime; SET @today = GETDATE()
SELECT DATEDIFF(yy, @dob, @today) -
CASE WHEN MONTH(@dob) > MONTH(@today) OR (MONTH(@dob) = MONTH(@today) AND DAY(@dob) > DAY(@today))
THEN 1 ELSE 0 END