Mega Code Archive

 
Categories / MSSQL Tutorial / Data Convert Functions
 

Use convert function with variables

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