Reporting Services - finding the current month through a expression - reporting-services

I would like to have a default value, that is the current year-month. Today my expression looks like this:
[Date Product Confirmed].[Date].[Yearmd].&[2013-03]
I would, or course, like to make the last part dynamic: &[2013-03].
Any suggestions?

You can try this:
="[Date Product Confirmed].[Date].[Yearmd].&[" & Cstr(Format(now(),"yyyy-MM")) &"]"

You can get the current year and month like that
=Format(Now(), "yyyy-MM")
Basically i getting the current date using Now()
and then i am formatting it yo be YYYY-MM

Related

Exctract Month and Day to create a date

I am trying to extract a numeric month and date from a give hire date to create an annual anniversary date in report builder.
Thus far I have tried the code below:
=Year(Now) +"-"+ Month(Fields!hire_date.Value) +"-"+ Day(Fields!hire_date.Value)
I got a #Error in the field I am trying to populate.
Looks to me like you're simply using the wrong syntax to concatenate the date. Additionally, you could simplify the expression using FORMAT. Try this:
=Year(Now()) & "-" & Format(Fields!hire_date.Value, "MM-dd")
This should return the date in the format 2019-06-21.
For other ways to format the date, see this link.

Week To Date Based Off Current Date

I am looking for an expression that will allow to me find the date of Monday of the week of my Date Field, to be used in a filter for a tablix.
Example, my date field today is 22/01/2019. I would like an expression that will return 21/01/2019. If the date was 26/01/2019, it should still return 21/01/2019.
For next week 31/01/2019 would return 28/01/2019.
Week starting Monday going to Sunday.
If its also possible for a similiar expression but to find the beginning of the month as well?
Is that possible?
Many thanks
To get the date of last Monday that occurred you can use something like
=Today.AddDays(1-WeekDay(Today(),FirstDayOfWeek.Monday))
and for the first of the month its just
=DateSerial(Year(Today()), Month(Today()), 1)
Both the above are based on the today() function, if you need them based on a date parameter, then the expression is a little different but your question stated "today".
monday of the week use the following expression:
DateAdd("d",DatePart(DateInterval.WeekDay,Fields!myDatefield.Value,0,0)+1,Fields!myDatefield.Value)
first day of the month use the following expression:
=DateAdd("d",-(Day(Fields!myDatefield.Value)-1), Fields!myDatefield.Value)

How To Specify Two Default Dates In Parameter

I'm using the following expression to pull a default date from yesterday:
=DateAdd("d",-1,Today())
The business requirements changed and now they want to see yesterday AND today. Is it possible to add onto this expression to include yesterday and today?
Just set the parameter to yesterday date and change this in your query.
WHERE [DateColumn] >= #DataParam
If you want to show the dates the report is using, try this in a textbox:
="Dates: " & Parameters!DateParam.Value & "-" Today()
UPDATE: If your parameter is multivalued you have to add two default values using these expression:
=Today()
=Today.AddDays(-1)
Then in your query change this:
WHERE [DateColumn] IN (#DateParam)
Let me know if this helps.

How to get current month name in SSRS?

I need current month name as default perameter name in my ssrs report. How can I get current month name using an ssrs expression?
For example "27-09-2012" would become "September"
and one more i need....
27-09-2012 to previous month name as well (August)
First question:
=MonthName(Month(Fields!datefield.Value))
Second question:
=MonthName(Month(DateAdd("m", -1, Today())))
I think the second question answer might be something like that, first converting the date to month then subtracting 1 from the month value and then converting it to month name.
Further reading:
SSRS Reports get Month name from Month Index or from date
Converting month number to month name in reporting services
OFF: I would change the date format you are using to 2012-09-27 as it works in every setting and should give you peace of mind when converting date formats.
Don't subtract 1 b/c it won't work for January.
Use this:
MonthName(Month(DateAdd("m", -1, CDate(Today))))
As a note, I tried the suggestion of =MonthName(Month(today())). What I would get is #error for whatever field the expression was in. However, =MonthName(str(Month(today()))) worked for me. I am unsure of whether or not the MonthName method changed to require a string or if it is some issue with my program. Just figured I would post this in case anyone else was having the same issue.
For Previous Month i found universal way : =MonthName(Month(CDate(Today()))-1,False) for SEPTEMBER (Full Month Name) 'OR'
=MonthName(Month(CDate(Today()))-1,True) for SEP (Short Month Name)

Reporting Services Remove Time from DateTime in Expression

I'm trying to populate an expression (default value of a parameter) with an explicit time. How do I remove the time from the the "now" function?
Something like this:
=FormatDateTime(Now, DateFormat.ShortDate)
Where "Now" can be replaced by the name of the date/time field that you're trying to convert.)
For instance,
=FormatDateTime(Fields!StartDate.Value, DateFormat.ShortDate)
Since SSRS utilizes VB, you can do the following:
=Today() 'returns date only
If you were to use:
=Now() 'returns date and current timestamp
=CDate(Now).ToString("dd/MM/yyyy")
Although you are hardcoding the date formart to a locale.
If you have to display the field on report header then try this...
RightClick on Textbox > Properties > Category > date > select *Format (Note this will maintain the regional settings).
Since this question has been viewed many times, I'm posting it... Hope it helps.
Just use DateValue(Now) if you want the result to be of DateTime data type.
If expected data format is MM-dd-yyyy then try below,
=CDate(Now).ToString("MM-dd-yyyy")
Similarly you can try this one,
=Format(Today(),"MM-dd-yyyy")
Output: 02-04-2016
Note:
Now() will show you current date and time stamp
Today() will show you Date only not time part.
Also you can set any date format instead of MM-dd-yyyy in my example.
In the format property of any textbox field you can use format strings:
e.g. D/M/Y, D, etc.
One thing that might help others is that you can place: =CDate(Now).ToString("dd/MM/yyyy") in the Format String Property of SSRS which can be obtained by right clicking the column. That is the cleanest way to do it. Then your expression won't be too large and difficult to visually "parse" :)
FormatDateTime(Parameter.StartDate.Value)
I'm coming late in the game but I tried all of the solutions above! couldn't get it to drop the zero's in the parameter and give me a default (it ignored the formatting or appeared blank). I was using SSRS 2005 so was struggling with its clunky / buggy issues.
My workaround was to add a column to the custom [DimDate] table in my database that I was pulling dates from. I added a column that was a string representation in the desired format of the [date] column. I then created 2 new Datasets in SSRS that pulled in the following queries for 2 defaults for my 'To' & 'From' date defaults -
'from'
SELECT Datestring
FROM dbo.dimDate
WHERE [date] = ( SELECT MAX(date)
FROM dbo.dimdate
WHERE date < DATEADD(month, -3, GETDATE()
)
'to'
SELECT Datestring
FROM dbo.dimDate
WHERE [date] = ( SELECT MAX(date)
FROM dbo.dimdate
WHERE date <= GETDATE()
)
My solution for a Date/Time parameter:
=CDate(Today())
The trick is to convert back to a DateTime as recommend Perhentian.
Found the solution from here
This gets the last second of the previous day:
DateAdd("s",-1,DateAdd("d",1,Today())
This returns the last second of the previous week:
=dateadd("d", -Weekday(Now), (DateAdd("s",-1,DateAdd("d",1,Today()))))
This should be done in the dataset. You could do this
Select CAST(CAST(YourDateTime as date) AS Varchar(11)) as DateColumnName
In SSRS Layout, just do this =Fields!DateColumnName.Value
Just concatenate a string to the end of the value:
Fields!<your field>.Value & " " 'test'
and this should work!