Home > SSRS Expert > SSRS – Beginning of the month

SSRS – Beginning of the month

Very often we need to process data from the beginning of month to the current day. So we need to write code to find the beginning of the month.

In SSRS, here is the VBA code you can use to default your report’s start date to the beginning of the month:

=DateAdd("D", -1.0 * DatePart("D", Today) + 1, Today)

image 

Of cause it’s easy to also get the current date as the end date:

image

If you want to do this in SQL, it’s very straightforward too:

DECLARE  @START_DT DATETIME, @END_DT DATETIME
IF    @START_DT    IS NULL
BEGIN
    SELECT @START_DT = DATEADD(DAY, -1, CONVERT(SMALLDATETIME, CONVERT(CHAR(8), GETDATE(), 1)))
    SELECT @END_DT = DATEADD(DAY, 1, @START_DT)
    SELECT @START_DT = DATEADD(DAY, -1*(DATEPART(DAY, @START_DT)) + 1, @START_DT)
    –SELECT @START_DT, @END_DT
END

image

Categories: SSRS Expert
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: