user3799005
user3799005

Reputation: 31

How to get the Start Date of the current Quarter populated in SSRS?

I am generating a report in SSRS, in which I got a start date field, which should populate the Start date of the current quarter automatically. Can someone please help me, how do I do this?. Thanks heaps

Upvotes: 3

Views: 7589

Answers (2)

stubaker
stubaker

Reputation: 1958

T-SQL for current quarter:

SELECT DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0) AS FirstDayOfCurrentQtr

Or SSRS expression if you want to set the value that way:

=DateAdd(DateInterval.Quarter, DateDiff(DateInterval.Quarter, CDate("1/1/1900"), Today()), CDate("1/1/1900"))

Upvotes: 9

Mark Wojciechowicz
Mark Wojciechowicz

Reputation: 4477

if you wanted to avoid having an additional dataset, you could use this expression as the default value for the parameter:

=DateSerial(Datetime.Today.Year,3 * ((datetime.Today.Month -1 )/3 + 1) -2, 1)

That's pretty ugly though. More ideally create a function that you cacan call that from the expression:

Function getQuarter (byVal d As DateTime) As DateTime

Dim quarter as Integer = (d.Month -1) / 3 + 1
Dim quarterStart  AS new DateTime(d.Year, 3 * quarter - 2, 1)
getQuarter = quarterStart

End Function

Put the above in the code section of the report properties and in the expression call it by:

=Code.GetQuarter(Today)

Upvotes: 0

Related Questions