?
Solved

Derive Quarter Begin Date

Posted on 2006-05-11
3
Medium Priority
?
297 Views
Last Modified: 2012-06-22
Does anyone have some simple code to derive the quarter begin date
from GetDate()?

Thanks.
0
Comment
Question by:JeffDrummond
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16662741
by quarter you mean 1.jan, 1.apr, 1.jul, 1.oct ?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16662755
first of month:
select dateadd(day, 1-datepart(day, getdate()), getdate())

first of quarter:
select dateadd( month,  1-datepart(month, getdate()) % 3   , dateadd(day, 1-datepart(day, getdate()), getdate()))
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 16662768
DECLARE @QBegin datetime

SET @QBegin = CONVERT(varchar, GetDate(), 101)
SET @QBegin = DATEADD(month, -(MONTH(@QBegin) % 3) + 1, @QBegin)
SET @QBegin = DATEADD(day, -DAY(@QBegin) + 1, @QBegin)
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question