title: Formatting Parameters in SSRS Report
body: <p>I have an SSRS report that takes 2 optional text parameters as below:</p>
  
  <ul>
  <li>StartDate, Text, allow Null, format YYYYMMDD</li>
  <li>EndDate, Text, allow Null. format YYYYMMDD</li>
  </ul>
  
  <p>I am trying to format a header text box that will show the below:</p>
  
  <p>If the parameters are Null, then I would get by default the Month Name and the Year (as the report will get data defaulted to the previous Month)</p>
  
  <p>If the parameters are set then I want to format them as dd MMMM YYYY (so <code>20141103</code> will be formatted as <code>03 November 2014</code></p>
  
  <p>Here is the code I am trying to use for the Expression in the text field:</p>
  
  <pre><code>= IIF(IsNothing(Parameters!StartDate.Value), 
      " for " &amp; MonthName(Month(DateAdd("m",-1,Today))) &amp; " " &amp; Year(DateAdd("m",-1,Today)), 
      "From " &amp; 
      RIGHT(Parameters!StartDate.Value,2) + " " + 
      MonthName(Month(
              LEFT(Parameters!EndDate.Value,4) + "-" +
              MID(Parameters!EndDate.Value,5,2) + "-" +
              RIGHT(Parameters!EndDate.Value,2)
          )) + " " 
      + LEFT(Parameters!StartDate.Value,4) + 
      " to " + 
      RIGHT(Parameters!EndDate.Value,2) + " " 
      + MonthName(Month(
              LEFT(Parameters!EndDate.Value,4) + "-" +
              MID(Parameters!EndDate.Value,5,2) + "-" +
              RIGHT(Parameters!EndDate.Value,2)
          )) + " " + 
      LEFT(Parameters!EndDate.Value,4))
  </code></pre>
  
  <p>so as you can see, if the parameter is Null (allowing for the report to default to run the last months data when scheduled) then the function should just show something like <code>December 2014</code> but if they are entered as YYYMMDD then I need to format them.</p>
  
  <p>I am getting the below error (in SSRS in Visual Studio 2013):</p>
  
  <pre><code>[rsRuntimeErrorInExpression] The Value expression 
  for the textrun ‘Textbox15.Paragraphs[0].TextRuns[0]’ 
  contains an error: Conversion from string "--" to type 'Date' is not valid. 
  </code></pre>
  
  <p>I have also tried using CDate around </p>
  
  <pre><code>LEFT(Parameters!EndDate.Value,4) + "-" +
  MID(Parameters!EndDate.Value,5,2) + "-" +
  RIGHT(Parameters!EndDate.Value,2)
  </code></pre>
  
  <p>(these should come out as <code>2014-11-01</code> for example) but again, no luck</p>
  
  <p>So where am I going wrong here and how can I format those dates if they are entered?</p>