DateDiff with DateTime in SSRS expression - reporting-services

I am trying to calculate the time difference between two DateTime parameters in a SSRS expression to display in DD:hh:mm:ss format. With the expression I am using I am getting:
Start: 03/04/2016 08:48:53 AM End: 03/07/2016 11:24:04 AM Elapsed: 74:33:11.
I would like to see Elapsed: 3:02:35:11 (days:hours:minutes:seconds).

Divide the hours by 24 to get Days, and then do a Modulo to get the remaining hours.

Try this:
=Floor(
DateDiff("s",Fields!ProcessOpened.Value,Fields!ProcessClosed.Value)
/ 86400) & ":" & Format(DateAdd("s",
DateDiff("s",Fields!ProcessOpened.Value,
Fields!ProcessClosed.Value), "00:00:00"), "HH:mm:ss")
I've tested with:
=Floor(DateDiff("s",CDATE("04/03/2016 08:48:53 AM"),
CDATE("07/03/2016 11:24:04 AM")) / 86400) & ":" &
Format(DateAdd("s", DateDiff("s",CDATE("04/03/2016 08:48:53 AM"),
CDATE("07/03/2016 11:24:04 AM")), "00:00:00"), "HH:mm:ss")
It returns:
3:02:35:11
Let me know if this helps.

Related

How to pass text in configuration file with a call to parameter

I have a package that sends emails, I have it set with a configuration file so I can pass a parameter with the addresses, attachments, etc. that I want to use, one of these parameters is the Message_source:
in which I pass the content of the email.
my problem comes in that I want to pass formatted text and a dynamic field (date).
how can I do this so I can send something like this:
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::Email_Content].Properties[Value]" ValueType="String">
<ConfiguredValue>here I want to pass a date, here is the date: #Date</ConfiguredValue>
</Configuration>
so I can generate something like this:
here I want to pass a date,
here is the date: 05-01-2023
I know that I can parse the date with:
RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
however adding this to the config file right away doesn't work.
If it's going to work, I think you're going to add in a few more levels of indirection.
What you want is to have an Expression as the content of a variable. It's happy to assign your string to the Value property but what is being sent is not the evaluated #Date but the literal characters # D A T E
<Configuration ConfiguredType="Property"
Path="\Package.Variables[User::Email_Content].Properties[Expression]" ValueType="String">
<ConfiguredValue>"I want to pass a date, here is the date: " + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())</ConfiguredValue>
</Configuration>
The same rules will apply with string building and all that so if you want to have it look like "I want to pass a date, here is the date: #Date" then you need to build out a valid expression. I'd create a Variable named Test and plug away until I get the syntax correct and then slap that, carefully, into your XML/dtsconfig
"I want to pass a date, here is the date: "
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
Finally, if that isn't working then ensure that #[User::Email_Content] has the EvaluateAsExpression property set to True

SSIS Filename variable with wildcards

I am looking at creating a SSIS package that copies the latest file from a specific directory. There are multiple files output to the directory each day and each gets date and time stamped in the file name
FLATFILE_20150909_130801.txt
FLATFILE_20150909_230508.txt
I am only interested in the latest file during the day. Which will always have the same prefix 23 . I’ve written the expression as
"\\\\DESTINATION\\FLATFILE"+ "_"+ (DT_STR,4,1252)DATEPART( "yyyy" , getdate() ) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" , getdate() ), 2) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , getdate() ), 2) + "_"+ "23"+ "****"+ ".sqb"
Which returns FLATFILE_20150909_23****.txt
Is there any way to assign wildcards to the characters in the string **** so it ignores these??

SSRS Format seconds as time (negative seconds)

I have a column with integers: TotalSec that has seconds. It can be 0, negative or positive.
I have to format these seconds in a report. But cant get something working for the negative seconds.
My logic:
For 0 = Nothing,
For Positive format as HH:mm:ss
For Negative - ABS the value then format as -HH:mm:ss
=IIF(SUM(Fields!TotalSec.Value)=0, Nothing, IiF(SUM(Fields!TotalSec.Value)>0,
Format(DateAdd("s",SUM(Fields!TotalSec.Value), "00:00:00"), "HH:mm:ss"), "-" & Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I get an #Error for the Negative numbers. With the warning:
Warning 2 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘TotalSec.Paragraphs[0].TextRuns[0]’ contains an error: The added or subtracted value results in an un-representable DateTime. Parameter name: value
It worked like this:
=IIF(SUM(Fields!TotalSec.Value)=0,Nothing,IIF(SUM(Fields!TotalSec.Value)< 0,"-"&Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss"),Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I cleaned up the previous answer:
=IIf(Fields!elapsed.Value < 0, "-", "+")
&
Format(
DateAdd(
"s",
Abs(Fields!elapsed.Value),
"00:00:00"
),
"HH:mm:ss" ' can be m:ss
)
The "+" is to keep the results lined up, and can be replaced with "" if desired.

Can I use leading zero in case of day in the Date field in SMTP

Can I use leading zero in case of day in the Date field in SMTP?
I mean smth like
03 Apr 2014 13:10:22 +0000
Can you quote RFC, please?
There are no dates in the SMTP protocol, but you are probably referring to email header fields as described by RFC 2822 Internet Message Format. From http://www.ietf.org/rfc/rfc2822.txt we have section 3.3 Date and Time specification, with the following selected fields:
date-time = [ day-of-week "," ] date FWS time [CFWS]
day-of-week = ([FWS] day-name) / obs-day-of-week
day-name = "Mon" / "Tue" / "Wed" / "Thu" /
"Fri" / "Sat" / "Sun"
date = day month year
year = 4*DIGIT / obs-year
month = (FWS month-name FWS) / obs-month
month-name = "Jan" / "Feb" / "Mar" / "Apr" /
"May" / "Jun" / "Jul" / "Aug" /
"Sep" / "Oct" / "Nov" / "Dec"
day = ([FWS] 1*2DIGIT) / obs-day
...
which states that the day part of the date should be between 1-2 digits, and this does not specifically prohibit using a leading zero. Nothing seems to be said about the optional leading zero, so proper interpretation should always allow it while parsing.
The obs- alternative variants describe old obsolete formats, e.g. 2-digit years and comments or folding white-space between any part.

IIF Statements with blank or alpha characters in MS Visual Basic

I have a field CODE_USER_2 that can be equal to 1.75, 2, 2.62, 3.75, 5.25, 6, OT(w/2 spaces, or __(4 spaces). If it is 1.75, 2, 2.62, 3.75, 5.25, 6 I would like corresponding weights to result (THIS PART WORKS).
If the field is __ or OT, I would like the equation to result with 0. I currently get #error with the following formula.
=IIf(Fields!CODE_USER_2_IM.Value= " " OR "OT " ,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895))
Please let me know if you have ideas!
You have to repeat "Fields!CODE_USER_2_IM.Value = " after the OR.
Or try this - less wordy but more obscure :
=IIf( ( " |OT |" ).Contains(Fields!CODE_USER_2_IM.Value + "|"
,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895
, True , 0))
Always close out a Switch with:
, True , [default value] )
Also beware that matching in SSRS expressions is exact e.g. 2 spaces not = 4 spaces.