DATEDIFF(d, @thisdate, @nextmonth) 'Days between' : DATEDIFF « Date Timezone « SQL Server / T-SQL






DATEDIFF(d, @thisdate, @nextmonth) 'Days between'

3> DECLARE @thisdate datetime, @nextmonth datetime
4>
5> SET @thisdate = GETDATE()
6> SET @nextmonth = DATEADD(m, 1, GETDATE())
7>
8> SELECT CONVERT(varchar, @thisdate, 101) 'Today',
9>     CONVERT(varchar, @nextmonth, 101) 'One month from today',
10>     DATEDIFF(d, @thisdate, @nextmonth) 'Days between'
11> GO
Today                          One month from today           Days between
------------------------------ ------------------------------ ------------
10/12/2006                     11/12/2006                               31

(1 rows affected)
1>
           
       








Related examples in the same category

1.DATEDIFF: return the difference between two dates
2.select DATEDIFF(second, '06:46:45', '11:35:00')
3.select DATEDIFF(quarter, '2001-12-01', '2002-09-30')
4.Find the number of days between 24th March 2001 and 24th March 1964
5.DATEDIFF(yyyy, "24 March 2001","24 March 1964")
6.DATEDIFF(mi, "24 March 2001","24 March 1964")
7.DATEDIFF(wk, "24 March 2001","24 March 1964")
8.DATEDIFF(m, "24 March 2001","24 March 1964")
9.DATEDIFF(month, '9-8-1989', '10-17-1991')
10.DATEDIFF(day, '9-8-1989', '10-17-1991')
11.Difference in weeks between 7-2-1996 and 8-4-1997
12.DATEDIFF(ss, @MyBirthDate, GETDATE())
13.select DATEDIFF(hour, '06:46:45', '11:35:00')
14.select DATEDIFF(minute, '06:46:45', '11:35:00')
15.Difference between the current time and UTC
16.DATEDIFF: date difference
17.Combine DateADD and DateDIFF to get the last date of a month
18.Passing a column name to the DATEDIFF() value argument