datediff

SQL Server find datediff between different rows, sum

一世执手 提交于 2019-12-20 05:35:10
问题 I am trying to build a query that analyzes data in our time tracking system. Every time a user swipes in or out, it makes a row recording the swipe time and On or Off site (entry or exit). In user 'Joe Bloggs' case there are 4 rows, which I want to pair and calculate a total time spent on site for Joe Bloggs. The problem is that there are records that are not as easy to pair. In the example given, the second user has two consecutive 'on's, and I need to find a method for ignoring repeated 'on

How can I use Datediff() in HQL

99封情书 提交于 2019-12-20 04:24:38
问题 I'm trying to get the difference between dates. In my SQL SERVER it's works fine: Select CSERVICE_ORDER_ID FROM TSERVICE_ORDERS WHERE DATEDIFF(DAY, CDB_CREATE_DATE_TIME, CCANCELLATION_DATE) = 4 But in my HQL query I'm not getting it. The function Datefiff works in HQL Query? Is there any function with the same behavior? 回答1: HQL doesn't support datediff, but if you still want to use datediff, you should use createNativeQuery() or createSQLQuery() to write that in sql. In your example, you

Is SQL DATEDIFF(year, …, …) an Expensive Computation?

不打扰是莪最后的温柔 提交于 2019-12-19 21:28:36
问题 I'm trying to optimize up some horrendously complicated SQL queries because it takes too long to finish. In my queries, I have dynamically created SQL statements with lots of the same functions, so I created a temporary table where each function is only called once instead of many, many times - this cut my execution time by 3/4. So my question is, can I expect to see much of a difference if say, 1,000 datediff computations are narrowed to 100? EDIT: The query looks like this : SELECT DISTINCT

Calculate DateDiff in SQL in Days:Hours:Mins:Seconds format

余生颓废 提交于 2019-12-19 19:44:45
问题 I am currently working an SQL script to calculate the difference between two dates which would give me the result in DD:HH:MI:SEC format. Example: Date 1: 7/30/12 4:00 PM Date 2: 5/4/12 10:31 AM And the result should be 87:05:29:00 Can you kindly help with the script for this? Regards, Arjun 回答1: If you are using sql-server then you can do this: declare @x int, @dt1 smalldatetime = '1996-03-25 03:24:16', @dt2 smalldatetime = getdate() set @x = datediff (s, @dt1, @dt2) SELECT convert(varchar,

Calculating difference of dates In Postgresql

不羁的心 提交于 2019-12-19 14:54:52
问题 I'm trying to find out the time between certain fields in my tables. However cause I'm using Postgresql :(( I can't use the DATEDIFF function. I can't find any clear guides/ tutorials on the net which shows how to do a similar thing in Postgres so I need help doing the same thing but in Postgres I'm assuming this query would work if I was using a RDBMS that supported the DATEDIFF function so basically my question is how can I change this so it works using features provided by Postgresql?

Calculating difference of dates In Postgresql

拟墨画扇 提交于 2019-12-19 14:52:10
问题 I'm trying to find out the time between certain fields in my tables. However cause I'm using Postgresql :(( I can't use the DATEDIFF function. I can't find any clear guides/ tutorials on the net which shows how to do a similar thing in Postgres so I need help doing the same thing but in Postgres I'm assuming this query would work if I was using a RDBMS that supported the DATEDIFF function so basically my question is how can I change this so it works using features provided by Postgresql?

DateTime::diff weired result

[亡魂溺海] 提交于 2019-12-19 04:57:17
问题 I use DateTime::diff to compare two DateTime , but the result is very weird as if abs($date1 - $date2) != abs($date2 - $date1) . $date1 = new DateTime("1980-11-21 00:00:00"); $date2 = new DateTime("1981-11-20 00:00:00"); var_dump($date1->diff($date2,true)->days); var_dump($date2->diff($date1,true)->days); var_dump($date1->diff($date2,true)->format("%Y-%m-%d %H:%i:%s")); var_dump($date2->diff($date1,true)->format("%Y-%m-%d %H:%i:%s")); Which returns: int(364) int(364) string(15) "00-11-30 00:0

How to find the difference between dates in VBA

佐手、 提交于 2019-12-18 07:42:26
问题 I am trying to find out the difference between the system date and the date stored in the worksheet. If the difference between them is > 30 days, the result is true, else the result is false Dim result as boolean Dim sDate as string sDate = Date if Worksheets("dates").Cells(1,1) - sDate > 30 then 'how do I do this? result = true else result = false end if How do I find out the difference in days between the system date and the date stored in the worksheet? The date in the worksheet can be a

DATEDIFF() or BETWEEN for Date Ranges in SQL Queries

半腔热情 提交于 2019-12-18 06:48:40
问题 I have recently been informed that the use of the BETWEEN method in SQL is somewhat unreliable, and I should therefore be using DATEDIFF() . However, another programmer has informed me this is not the case and the BETWEEN method works brilliantly in all cases as long as the date is formatted correctly. Please could someone settle this debate by stating which method is better and why? At the moment my date range SQL looks like this: DATEDIFF(d,'01-Jan-1970',SIH.[Something_Date]) >= 0 AND

PHP Difference in months between two dates? [duplicate]

倖福魔咒の 提交于 2019-12-18 05:43:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to calculate the difference between two dates using PHP? Date Difference in php? I have two dates in a variable like $fdate = "2011-09-01" $ldate = "2012-06-06" Now I need the difference in months between them. For example, the answer should be 10 if you calculate this from month 09 (September) to 06 (June) of next year - you'll get 10 as result. How can I do this in PHP? 回答1: A more elegant solution is to