Calculating days from two dates - report-viewer2010

So i have a report viewer showing data but in one of my columns i want to show the calculated days based off the previous two columns of dates in an expression property i can apply for the text box. Example of what i am trying to do
8/1/2011 8/19/2011 18 days

(endDate - startDate).TotalDays
Substraction on two DateTimes produces TimeSpan object, which has TotalDays property
Or try DateDiff("d", endDate, startDate) (for Visual Basic only)

Related

Spotfire change datetime column to monday of weekday

im using spotfire software and i have a datetime column like:
DateTime
21/07/2022 12:11:01
21/07/2022 14:32:01
04/12/2022 10:22:01
30/06/2022 16:22:01
how can i created a new calculated column where it instead changes the date to the monday of the week for all values?
many thanks
i can do this in power bi by dropping the time and using the function
Start of Week Monday = 'Data'[DateTime ]+1-WEEKDAY('Data'[DateTime ]-1)
this results in all the values changing to the monday of its given week/month/year
how can i do this in spotfire?
Assuming you have the following functions available to you: DateAdd, DayOfWeek (*)
You could try:
DateAdd("dd",1 - (If(DayOfWeek([original_Date])=0,7,DayOfWeek([original_Date]))),[original_Date])
This resets the date (including the time portion) to the previous Monday.
Initially I had tried the simpler formula:
DateAdd("dd",1 - DayOfWeek([original_Date]),[original_Date])
but Sunday is mapped to a zero, so whenever the original day was a Sunday, it was pushed to the following Monday.
It does depend on your original settings so you may have to play around with the numbers a bit.
(*) depending on what the source of your data is, equivalent functions may be available.

Is it possible to print the official calendar week range and not just the available dates in my dataset?

I have a data frame which sums values over a weekly basis.
I am able to calculate the official calendar week that the summed values fall into in each case, but I want to know if I can add the calendar week range also for reference as some values only contain a couple of days' worth of dates for a particular week.
I currently use paste(min(created), max(created), sep = ' - ') but this only gives me the range of values with created and not the official calendar week range and can sometimes be misleading due to an incomplete weeks' worth of values being present in the dataset, as mentioned above.
Can an official calendar week range be achieved?

Calculating days difference in a calculated field

I have tried every variation I can think of.
I have a table that displays [Appt Date] in a field. I want to subtract that date from today to give me the [Days to Appt].
I have tried several variations in the expression builder of the calculated field
=DateDiff("d",[Appt Date]-Date())
=[Appt Date]-Date()
And so on.
The error message I am continuously presented with is
The Expression [APPT Date]-Date() cannot be used in a calculated column.
I have tried this in a Date/Time calculated field and a Number Calculated Field
Your help will be gratefully appreciated
First, don't use calculated fields. Use a query, that's what they are for.
Second, use the correct syntax for DateDiff:
Select *, DateDiff("d", Date(), [Appt Date]) As Days From YourTable
If [Appt Date] holds date values with no time part, you can even get away with:
Select *, [Appt Date] - Date() As Days From YourTable
If [Appt Date] is not of data type Date, first convert to Date:
Select *, DateDiff("d", Date(), DateValue([Appt Date])) As Days From YourTable
Select *, DateValue([Appt Date]) - Date() As Days From YourTable
Comparing dates seems to be difficult. Developing a calendar by myself I found out, that Microsoft Access 2010 give very different values for apparently equal Dates / times. To compare dates for me is first to calculate the date as a long value.
Dim longTermDate As Long
longTermDate = CLng(PubDateDateActual * 10000)
Then the float behaviour of a date or time may be avoided if
truncated by cutting off the right portion of the date.
Then I can compare dates. And my calendar app works.
Best regards from Ottobrunn, Bavaria, germany

How to calculate number of days by two dates in SSRS formula field

I have an SSRS report and I have a table there, in which I have a column named as No. Of Days which are lying between two dates. I am getting those dates (datetime) through datasource but don't know how to calculate number of days between these two dates in a tablix cell formula.
The following will get the difference between two dates:
=DateDiff("d","01-Jun-2011","10-Jun-2011")
which results in 9.
In a table cell it will be something like:
=DateDiff("d",YourDataSet.Fields!FirstDate.Value, YourDataSet.Fields!SecondDate.Value)

Formatting time in SQL as day.hour

I'm creating a report from a stored procedure that pulls two date/times (CreatedDate and ClosedDate). I need a column on the report that shows the difference (i.e. time it took to go from open to close). First, I just subtracted CreatedDate from ClosedDate (in the report [SQL Server Reporting Services], not in the stored procedure) and got a time that looks like this: 72.20:34:18.6230000 (day.hour:minute:second). I need to shrink this down, if possible, to just day.hour...
I was experimenting with some of the functions found on MSDN (http://msdn.microsoft.com/en-us/library/ms186724.aspx). DATEDIFF almost gives me what I need, but I can only specify days or hours, and ideally (as I said), I need it to show the 'time to close' as both (day.hour).
Is this possible?
In SSRS, you can apply a custom format to that column to show only days.hours. Right click the column in design mode -->text box properties-->Number(on left hand side). If you don't see one of the formats for date, time or number that fits what you need, create a custom one at the bottom.
Convert to minutes
divide by 1440 gives whole days
modulo 1440 gives remaining minutes, divide by 60 for hours
Something like (not tested):
SELECT
CAST(DATEDIFF(minute, CreatedDate, ClosedDate) / 1440 AS varchar(20)) + '.'
CAST((DATEDIFF(minute, CreatedDate, ClosedDate) % 1440) / 60 AS varchar(20))
FROM
MyTable
You may need to fiddle with the hours representation in cade I've misunderstood
DATEDIFF for day and hour go by boundaries: that is if there are just 3 minutes between the 2 values spanning midnight, there will be one hour/day difference. So I used minutes
Edit:
To overflow the int from DATEDIFF requires a difference of 4000+ years
Thoughts:
Using datetime2 and have CreatedDate of lowest 0001-01-01
ClosedDate is a sentinel value like 9999-12-31 say for "open" items
CreatedDate and ClosedDate are varchar and conversion to datetime is faulty
Your example shows 72 days difference which would be around 104k minutes.
I would try this to see where you have more than 1000 year differences which would be a mere half billion or so minutes:
SELECT * FROM mytables
WHERE DATEDIFF(year, CreatedDate, ClosedDate) > 1000

Resources