Set default parameter dates to start and end of month

Situation
The requirement in a lot of my reports in SSRS has always been a date range rather than just the one date. The user must be allowed to select all results between two dates instead of just specifying the one day. If the second parameter (ToDate) is the same as the first (FromDate), then the range is for that particular date.

Solution
Easy for some but anything that I spend 30 minutes googling and reading up on is asking for an article on my own site. Besides this is how I did it and what worked for me...

Set the default values for your from and to date respectively:
copyraw
-- From Date (european format - dd/mm/yyyy)
=CDate("01/" + cstr(month(today.now())) + "/" + cstr(year(today.now())))

-- To Date (european format - dd/mm/yyyy)
=dateadd("d",-1, CDate("01/" + cstr(month(today.now())+1) + "/" + cstr(year(today.now()))) )

-- From Date (american format - mm/dd/yyyy)
=CDate(cstr(month(today.now())) + "/1/" + cstr(year(today.now())))

-- To Date (american format - mm/dd/yyyy)
=dateadd("d",-1, CDate(cstr(month(today.now())+1) + "/1/" + cstr(year(today.now()))) )
  1.  -- From Date (european format - dd/mm/yyyy) 
  2.  =CDate("01/" + cstr(month(today.now())) + "/" + cstr(year(today.now()))) 
  3.   
  4.  -- To Date (european format - dd/mm/yyyy) 
  5.  =dateadd("d",-1, CDate("01/" + cstr(month(today.now())+1) + "/" + cstr(year(today.now()))) ) 
  6.   
  7.  -- From Date (american format - mm/dd/yyyy) 
  8.  =CDate(cstr(month(today.now())) + "/1/" + cstr(year(today.now()))) 
  9.   
  10.  -- To Date (american format - mm/dd/yyyy) 
  11.  =dateadd("d",-1, CDate(cstr(month(today.now())+1) + "/1/" + cstr(year(today.now()))) ) 
This idea was based on Bob Griffin's post on SQL Server Central.com forums where he subtracts 1 day from the first day of next month to get the last date/number of days in this month.
Category: SQL Server Reporting Services :: Article: 337

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Joes Word Cloud

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.