Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

ChangeDateTpFirstOfNextMonth Expand / Collapse
Author
Message
Posted Thursday, August 7, 2008 9:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 16, 2014 7:30 AM
Points: 7, Visits: 177
Comments posted to this topic are about the item ChangeDateTpFirstOfNextMonth
Post #548368
Posted Thursday, August 14, 2008 1:33 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 11, 2014 3:53 AM
Points: 292, Visits: 665
If your want to remove the time portion of the result you could use this - select dateadd(month,datediff(month,-1,getdate()),0)


Post #552459
Posted Thursday, August 14, 2008 5:12 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 9, 2014 4:10 PM
Points: 1,388, Visits: 239
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))
Post #552572
Posted Thursday, August 14, 2008 11:38 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 2:15 PM
Points: 533, Visits: 785
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
Post #552948
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse