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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 quarter
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 05/08/2013 :  06:52:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 05/08/2013 :  09:09:52  Show Profile  Reply with Quote
DATEADD(mm,1,DATEADD(qq,DATEDIFF(qq,0,YourDateColumnHere),0)-1)
Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 05/08/2013 :  09:56:04  Show Profile  Reply with Quote
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 - 05/08/2013 :  15:24:25  Show Profile  Reply with Quote
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.

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

MJ
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000