27 May 2009

SSRS: Current Month Date Parameter Defaults

Now and again, I have to pretend that I am a report monkey. SQL Server Reporting Services makes that easy, since most of things are relatively intuitive. Today, I got to figure out (and by 'figure out,' I mean 'Google') the easiest way to create report parameters that default to the first and last days of the current month. The following is what I came up... Surprised that there is not a function to readily do this. So, without further ado, for my future reference, I present the following expressions.

The first of the current month:

dateserial(year(Today), month(Today), 1),
DateFormat.ShortDate -- Format as mm/dd/yyyy

The last day of the current month:
dateserial(year(Today), month(Today), 1)

And free of formatting and comments, for your copy-and-paste convenience:

=FormatDateTime(dateserial(year(Today),month(Today),1), DateFormat.ShortDate)

=FormatDateTime(DateAdd("d", -1, DateAdd("m", 1, dateserial(year(Today),month(Today),1))), DateFormat.ShortDate)

No comments: