Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS expression to get the year from the DateAdd()

I am trying to get the year part from the DateAdd function. I am going wrong some where. I tried many methods but still hit with he error

Datepart("yyyy", DateAdd("M",-2,Now)) This does not work. Can you help

like image 315
user2637506 Avatar asked Oct 15 '13 10:10

user2637506


2 Answers

It looks like you're trying to get the year for the day two months ago:

=DatePart(DateInterval.Year, DateAdd(DateInterval.Month, -2, Now()))

Edit after comment

In your expression in the comment you're getting an error trying to add a string and an integer together.

So it looks like the actual requirement is to get a string like {Month name}-{year}.

You can do this by applying a Format expression to the date, either in the textbox directly:

=Format(DateAdd(DateInterval.Month, -2, Now()), "MMMM-yyyy")

Or add MMMM-yyyy as the Format property to a textbox with the very first expression:

enter image description here

Either way, for today you get:

enter image description here

like image 159
Ian Preston Avatar answered Sep 17 '22 16:09

Ian Preston


  • MonthName(Month(DateAdd("M",-2,Now))) + " - " + DatePart(DateInterval.Year, DateAdd(DateInterval.Month, -2, Now))

This also workes when we replace '+' with '&' symbol...

  • MonthName(Month(DateAdd("M",-2,Now))) & " - " & DatePart(DateInterval.Year, DateAdd(DateInterval.Month, -2, Now))
like image 38
user2637506 Avatar answered Sep 18 '22 16:09

user2637506