Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 quarter

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-05-08 : 06:52:04
hi,
how do I get the last date of the first month in the quaretr?
For example you are given the date: 31 march 2013
The date I am after is to get 31 jan 2013
My following sql only shows the first day of the quarter wheras I want to get the last day of it.
Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-08 : 09:09:52
[code]DATEADD(mm,1,DATEADD(qq,DATEDIFF(qq,0,YourDateColumnHere),0)-1)[/code]
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-05-08 : 09:56:04
quote:
Originally posted by James K

DATEADD(mm,1,DATEADD(qq,DATEDIFF(qq,0,YourDateColumnHere),0)-1)



Thanks
Go to Top of Page

Mike Jackson
Starting Member

37 Posts

Posted - 2013-05-08 : 15:24:25
You might consider a calendar table. It takes a few minutes to setup but can save you lots of time in the future for search such as these.

[url]http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html[/url]

MJ
Go to Top of Page
   

- Advertisement -