locked
Working with dates in expressions RRS feed

  • Question

  • Why do I get a # Error when running a report with the below expression?

    =Fields!Time_Begin.Value+Fields!Current_Contract_Days.Value

    Monday, July 22, 2013 1:52 PM

Answers

  • 450 was the sample data.  That expression would add 450 to every record but each record may have a different Current Contract Days.

    What I want to do is take a date field (Fields!Time_Begin.Value) and add a number field (Fields!Current_Contract_ Days.Value) to produce a new date.

    Hi,

    I tried your scenario , it works perfectly

    below is the expression for New Date :

    =FormatDateTime(DateAdd("d", Fields!Current_Contract_Days.Value, Fields!Time_Begin.Value), DateFormat.ShortDate)


    sathya --------- Mark as answered if my post solved your problem and Vote as helpful if my post was useful.

    • Marked as answer by PKA55 Tuesday, July 23, 2013 6:15 PM
    Tuesday, July 23, 2013 5:49 PM

All replies

  • Hi PK,

    You cant add the different data types fields in a expression. As per my knowledge,

    Fields!Time_Begin.Value = Datetime value

    Fields!Current_Contract_Days.Value = Number of days

    You can't add the values. If you are trying to display then use it as:

    =Fields!Time_Begin.Value &"-" & Fields!Current_Contract_Days.Value

    For example: Fields!FieldName.Value & " - " & Fields!FieldName.Value

    For more information on expressions:

    http://www.msbimaru.blogspot.dk/2011/03/ssrs-expressions.html

    http://www.msbimaru.blogspot.dk/2013/01/some-more-ssrs-expressions-collection.html


    Maruthi...



    Monday, July 22, 2013 3:32 PM
  • Hi,

    Is Time_Begin & Current_Contract_Days are of same/compatible  type .

    Try this link for converting to appropriate data types in SSRS - http://msdn.microsoft.com/en-us/library/dd255246.aspx

    Common Date Expressions - http://bidn.com/blogs/DevinKnight/ssis/381/ssrs-commonly-required-date-expressions

    Can you post error description ?


    sathya --------- Mark as answered if my post solved your problem and Vote as helpful if my post was useful.

    Monday, July 22, 2013 3:34 PM
  • Thanks for the responce Sathya, No the 2 fields are not the same data type.  One is a Date and the other a number.  I am trying to calculate a new date by adding a number of days to an existing date. There is no other error message but #Error. 

    Tuesday, July 23, 2013 3:17 PM
  • Thanks Maruthi,

    Well I'm stuck if you can't use different data types in an expression.  But you would think something Excel and Access does so easily can also be done in Report Builder.

    Tuesday, July 23, 2013 3:26 PM
  • Thanks Maruthi,

    Well I'm stuck if you can't use different data types in an expression.  But you would think something Excel and Access does so easily can also be done in Report Builder.

    Hi ,

    Post both fields (Fields!Time_Begin.Value , Fields!Current_Contract_Days.Value ) data type ,

    Sample data  and expected output ...


    sathya --------- Mark as answered if my post solved your problem and Vote as helpful if my post was useful.

    Tuesday, July 23, 2013 4:03 PM
  • Fields!Time_Begin.Value  - Date field - sample data 08/01/2012

    Fields!Current_Contract_Days.Value  - Number Field - sample data 450

    Expected outpout = 9/5/2013 

    Thanks for the help!

    Tuesday, July 23, 2013 4:40 PM
  • Try like this,

    =DateAdd("d", 450, Fields!Time_Begin.Value)


    sathya --------- Mark as answered if my post solved your problem and Vote as helpful if my post was useful.

    Tuesday, July 23, 2013 5:15 PM
  • 450 was the sample data.  That expression would add 450 to every record but each record may have a different Current Contract Days.

    What I want to do is take a date field (Fields!Time_Begin.Value) and add a number field (Fields!Current_Contract_ Days.Value) to produce a new date.

    Tuesday, July 23, 2013 5:31 PM
  • 450 was the sample data.  That expression would add 450 to every record but each record may have a different Current Contract Days.

    What I want to do is take a date field (Fields!Time_Begin.Value) and add a number field (Fields!Current_Contract_ Days.Value) to produce a new date.

    Hi,

    I tried your scenario , it works perfectly

    below is the expression for New Date :

    =FormatDateTime(DateAdd("d", Fields!Current_Contract_Days.Value, Fields!Time_Begin.Value), DateFormat.ShortDate)


    sathya --------- Mark as answered if my post solved your problem and Vote as helpful if my post was useful.

    • Marked as answer by PKA55 Tuesday, July 23, 2013 6:15 PM
    Tuesday, July 23, 2013 5:49 PM
  • Thanks so much!!  It works!!!

    Tuesday, July 23, 2013 6:42 PM