Reputation: 4915
I need to get the tsql datetime of the first day of the current month to use in a query.
I have come up with
declare @StartDate datetime
set @StartDate = cast( MONTH( getdate()) as char(2))+ '/1/'
+ cast( Year( getdate()) as char(4))
select @StartDate
But was wondering about a better way to do this.
Suggestions?
Upvotes: 0
Views: 77
Reputation: 247760
How about this:
SELECT DATEADD(month, DATEDIFF(month, 0, getdate()), 0) AS FirstOfMonth
Upvotes: 4