Exctract Month and Day to create a date - reporting-services

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.

Related

Conditional formatting for current day date

I am just trying to getting my data to do a color fill if the date value equals today.
The data is coming from oracle:
=IIf(Fields!finishDATE.Value = Today(),"Yellow","Transparent")
This will not give me any errors nor will it do the function according to the expression. None of the data with the finish date equaling today highlights.
If today is 8/24/2021 it should look like this:
3/22/2021, 8/24/2021, 2/22/2021
As I'm not sure what format the data will come in from Oracle (I'm a MS SQL person) then this might be overkill but try this
=IIF (Format(Fields!finishDATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"), "Yellow", Nothing)
All I'm doing here is comparing just the date parts of the date/datetime values.
Below is the output. The first column is the actual date column contents including a time, then for illustration only, the 2nd column shows it formatted to just the date part and the 3rd column show today() with the same format applied.
Finally, I used the keyword Nothing (SSRS almost equivalent of NULL) as this is the correct default 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.

Date conversion in SSIS

anyone has an idea how to convert date to the format for example Monday,15-January-1990 in SSIS.
This is what I tried converting birthdate to the example format above:
(DT_STR,10,1252)DAY(BirthDate) + ","
+ (DT_STR,2,1252)DATEPART("dd",BirthDate)
+ "-" + (DT_STR,15,1252)MONTH(BirthDate)
+ "-" + (DT_STR,4,1252)DATEPART("yy",BirthDate)
The example output i get is this : 1,1-9-1965.
What you've done so far is as far as you can get with built-in SSIS Date/Time functions.
AFAIK, SSIS does not have a built-in WEEKFDAYNAME or MONTHNAME functions. You can see that even in the Expression Builder, under Date/Time Functions, there are only the following. MONTH returns interger of month and DAY returns the actual date, not the weekday. To get the weekday, you have to pass in "dw" as a parameter to the DATEPART function (see example below). Today is Thu = weekday #5
That said, there are a couple of "round about ways" to achieve what you want.
1. Use a scripting Task or Scripting Component to take in a date parameter and output the translated / transformed date string.
2. Use a couple of variables and an expression task as detailed here => SSIS - How To Use Expression Task To Get Day Name and Month Name In SSIS Package

Reporting Services - finding the current month through a expression

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

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!