I want to get the Turn Around Time(TAT) of dates. for example:
I have a createddatetime 2016-11-02 06:21:34.000 and endeddatetime 2016-11-02 22:00:00.000. I want to get the difference of two dates by 2 decimal places. Anyone can help for the SSRS expression needed to perform this?
Result for the above diff is 0.67
TIA!
With number formatting set to Number with 2 decimal places, this expression gives you the same result as your SQL statement:
=Round(DateDiff(DateInterval.Second,Fields!FirstDate.Value,Fields!SecondDate.Value) /60 / 60, 0) / 24
You need to calculate the number of seconds and round this as an hour value to emulate the behaviour of SQL's DATEDIFF function as the .NET version only considers complete units when comparing dates. See this question for further details of this: SQL Server DateDiff Vs .Net DateDiff.
If you just used:
=DateDiff(DateInterval.Day,Fields!FirstDate.Value,Fields!SecondDate.Value)
then you'll get a result of 0.00 as there are no complete days between these dates, rather than the 0.65 you get from the SQL statement.
Similarly, if you try:
=DateDiff(DateInterval.Hour,Fields!FirstDate.Value,Fields!SecondDate.Value) / 24
you'll get a result of 0.63, as the number of complete hours between your dates is 15 and 15 / 24 = 0.625.
Related
I am writing a query that is used by report generating software.
Part of this is querying for the hours needed to complete a project. We record this a 2 decimal float so that we can estimate to the quarter hour.
However, if we are using it in our report and the hour we recorded is something like 8.00, I want to query it and format it so that 8.00 is just 8. However any hours with something past the decimal, like 8.25, should remain as 8.25. How can I make this work?
hours Queried Result
====== -> My Query -> ==============
8.00 8
8.25 8.25
I am using MySQL 5.6
You can use the REPLACE() function to remove .00:
REPLACE(hours, '.00', '') AS hours
You can convert it to a string and check the rightmost 2 characters and trim those if they are '00'.
SELECT TRIM(TRAILING '.00' FROM CAST(column_name AS VARCHAR));
SELECT REPLACE(Round(8.00), '.00', ' ');
I will give more example so you can clear your Logic:
MySQL ROUND() rounds a number specified as an argument up to a number specified as another argument.
Syntax:
ROUND(N,[D]);
Where 'N' is rounded up to D decimal places.
and 'D' is indicating up to how many decimal places N will be rounded.
Example 1:-
SELECT ROUND(4.43);
Output :-
4
The above MySQL statement will round the given number 4.43. No decimal places have been defined, so the default decimal value is 0.
Example 2:-
SELECT ROUND(-4.53);
Output:-
-5
The above MySQL statement will round the given number -4.53. No decimal places have been defined, so the default decimal value is 0.
In my project in SQL Server 2014, I am creating a table on the fly with
select
Region_Code,
'9999999' as [Avg Time to Dispatch in Minutes],
999999999.9999 as [Avg Time to Dispatch in Hours]
from
table1
into
TempTable1
I notice when I look at the design view of this table I created that the 3rd column is of type Numeric(13,4).
I then update this table with real values and get:
region AvgTimeToDispatchInMinutes AvgTimeToDispatchInHours
Maine 393 999999999.9999
I want to get the AvgTimeToDispatchInHours so I do:
UPDATE TempTable1
SET [Avg Time to Dispatch in Hours] = [Avg Time to Dispatch in Minutes] / 60
I am getting 6.00 instead of 6.6 which is what I want.
How can I get 6.6 or the number not being rounded?
You're doing an integer division:
SELECT 393 / 60
results in 6 as you said (because it answers the question: how many times can 60 fit in 393 wholly?).
If you need fractional values, you need to convert at least one of the numbers involved to a fractional type, e.g. decimal - the easiest would be like this:
SELECT 393 / 60.0
which returns 6.55 as expected
how can i find the difference between two dateTime store in a MySQL database
e.g the difference in hours between 2016-03-09 04:30:00 and 2016-03-10 03:00:00.
i have tried dateDiff() but it does not compare the hours that is need to see the difference between (2016-03-09 04:30:00) - (2016-03-10 03:10:00).
the order is year-month-day time
The output i need is the number of hours between these times also considering the time as well.
You can use TIMESTAMPDIFF to find the difference between two timestamps
SELECT TIMESTAMPDIFF(HOUR,'2009-05-18 10:00','2009-05-18 11:00');
If you want fraction(eg: 1.5 hrs) hours you can do like below
SELECT (UNIX_TIMESTAMP('2012-10-30 10:40')-UNIX_TIMESTAMP('2012-10-30 10:30'))/3600 hour_diff
One simple method is to use to_seconds():
select to_seconds(dt1) - to_seconds(dt2)
This gives the difference in seconds. Then you can divide by 60*60 to get hours or 24*60*60 for days.
For the leave application, FROM date and TO date is given by selecting the dates from calender. I have these two dates in mysql.I want to calculate number of days for the leave. So Person applying leave from July 1 to July 5 th. So total 5 days.
But when i use DateDiff(to, date) it gives 4.
How can i get 5 days?
select datediff('2015-07-05','2015-07-01');
You may simply do +1, as you already notice, DATEDIFF excludes starting date, see example below:
select (datediff('2015-07-05','2015-07-01') + 1) as days
DATEDIFF(expr1,expr2)
DATEDIFF() returns expr1 − expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.
example
SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
output : 1
or
SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');
Output : 31
You can add manual plus 1
If you closely look at datediff function,
when you use two same dates, it will give you 0 days as a difference, not 1.
select datediff('2015-07-01','2015-07-01');
Will give you 0 days.
So its obvious that you will get one less day as it starts with 0 difference for same date.
datediff will return difference between two dates however you need to include both the dates while calculating the number of leaves. You should use value returned from datediff + 1.
My DB values save in this format
"12:07 AM"
dataType varchar in Sql Server
i want minutes b/w 2 times 2nd time is
current time
23:50 AM
23:24:43.6100000
differnce 26 minutes
but output come in negative values by executing below query
here m trying to do but output come in negative values
select datediff(minute,cast(getdate() as time),OrderDeliverTime)
from tblOrder
If the OrderDeliverTime occurs in the past, then it should be the middle parameter in DateDiff:
select datediff(minute,OrderDeliverTime,cast(getdate() as time)) from tblOrder