|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 12:25 PM
Points: 7,
Visits: 123
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 7:08 AM
Points: 292,
Visits: 657
|
|
If your want to remove the time portion of the result you could use this - select dateadd(month,datediff(month,-1,getdate()),0)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 12:13 PM
Points: 1,388,
Visits: 235
|
|
Alternately, you can also use the DATEPART function instead of DATEDIFF:
DECLARE @Date DATETIME SET @Date = GETDATE() SELECT DATEADD(MONTH,1,DATEADD(DAY, (-1 * DATEPART(DAY,@Date)) + 1, @Date))
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, February 27, 2012 9:14 AM
Points: 501,
Visits: 783
|
|
You can truncate the time part and simplify the calculation in one swell foop:
select DateAdd( m, DateDiff( m, 0, @NextMonth ) + 1, 0 ); Leave out the "+ 1" and you get the first day of this month.
Tomm Carr -- Version Normal Form -- http://groups.google.com/group/vrdbms
|
|
|
|