datediff

Only show hours in MYSQL DATEDIFF

♀尐吖头ヾ 提交于 2019-11-27 22:41:53
I've been busy with this for hours, but I cant get it to work. SQL SELECT DATEDIFF(end_time, start_time) as `difference` FROM timeattendance WHERE timeattendance_id = '1484' start_time = 2012-01-01 12:00:00 end_time = 2012-01-02 13:00:00 The difference is 25 (hours). But the output I get is 1 (day). How can I get the 25 hours as output? FlyingMolga What about using TIMESTAMPDIFF ? SELECT TIMESTAMPDIFF(HOUR, start_time, end_time) as `difference` FROM timeattendance WHERE timeattendance_id = '1484' You better use TIMEDIFF instead of DATEDIFF since DATEDIFF casts all times to dates before

SQL Datediff - find datediff between rows

给你一囗甜甜゛ 提交于 2019-11-27 19:52:23
I would like to query a database using sql to show the difference in time between id 1,2,3 and so on. basically it will compare the row below it for all records. any help would be appreciated. IDCODE DATE TIME DIFFERENCE (MINS) 1 02/03/2011 08:00 0 2 02/03/2011 08:10 10 3 02/03/2011 08:23 13 4 02/03/2011 08:25 2 5 02/03/2011 09:25 60 6 02/03/2011 10:20 55 7 02/03/2011 10:34 14 Thanks! If using SQL Server, one way is to do: DECLARE @Data TABLE (IDCode INTEGER PRIMARY KEY, DateVal DATETIME) INSERT @Data VALUES (1, '2011-03-02 08:00') INSERT @Data VALUES (2, '2011-03-02 08:10') INSERT @Data

Calculating time difference by ID

送分小仙女□ 提交于 2019-11-27 15:45:32
I have data like this: Incident.ID.. = c(rep("INCFI0000029582",4), rep("INCFI0000029587",4)) date = c("2014-09-25 08:39:45", "2014-09-25 08:39:48", "2014-09-25 08:40:44", "2014-10-10 23:04:00", "2014-09-25 08:33:32", "2014-09-25 08:34:41", "2014-09-25 08:35:24", "2014-10-10 23:04:00") df = data.frame(Incident.ID..,date, stringsAsFactors = FALSE) df Incident.ID.. date 1 INCFI0000029582 2014-09-25 08:39:45 2 INCFI0000029582 2014-09-25 08:39:48 3 INCFI0000029582 2014-09-25 08:40:44 4 INCFI0000029582 2014-10-10 23:04:00 5 INCFI0000029587 2014-09-25 08:33:32 6 INCFI0000029587 2014-09-25 08:34:41 7

SQL Server Group By Month

戏子无情 提交于 2019-11-27 10:06:26
问题 I have a table which has this schema ItemID UserID Year IsPaid PaymentDate Amount 1 1 2009 0 2009-11-01 300 2 1 2009 0 2009-12-01 342 3 1 2010 0 2010-01-01 243 4 1 2010 0 2010-02-01 2543 5 1 2010 0 2010-03-01 475 I'm trying to get a query working which shows the totals for each month. So far I've tried DateDiff and nested selects, but neither gives me what I want. This is the closest I have I think: DECLARE @start [datetime] = 2010/4/1; SELECT ItemID, IsPaid, (SELECT SUM(Amount) FROM Payments

Is it possible to set start of week for T-SQL DATEDIFF function?

左心房为你撑大大i 提交于 2019-11-27 09:05:13
I use DATEDIFF function to filter records added this week only: DATEDIFF(week, DateCreated, GETDATE()) = 0 and I noticed what it's assumed what week starts on Sunday. But in my case I would prefer to set start of week on Monday. Is it possible somehow in T-SQL? Thanks! Update: Below is an example showing what DATEDIFF doesn't check @@DATEFIRST variable so I need another solution. SET DATEFIRST 1; SELECT DateCreated, DATEDIFF(week, DateCreated, CAST('20090725' AS DATETIME)) AS D25, DATEDIFF(week, DateCreated, CAST('20090726' AS DATETIME)) AS D26 FROM ( SELECT CAST('20090724' AS DATETIME) AS

Calculate exact date difference in years using SQL

佐手、 提交于 2019-11-27 07:43:25
问题 I receive reports in which the data is ETL to the DB automatically. I extract and transform some of that data to load it somewhere else. One thing I need to do is a DATEDIFF but the year needs to be exact (i.e., 4.6 years instead of rounding up to five years. The following is my script: select *, DATEDIFF (yy, Begin_date, GETDATE()) AS 'Age in Years' from Report_Stage; The 'Age_In_Years' column is being rounded. How do I get the exact date in years? 回答1: Have you tried getting the difference

Calculate month difference in Joda Time

旧巷老猫 提交于 2019-11-27 06:52:36
问题 At the 4th line of code (ignore whitespace & comments) and beyond I'm calculating the month difference between 2 dates. This works, but looks a bit hacky. Is there a better way? int handleAllowance(LocalDate today) { int allowance = membership.allowance(); if (allowance == 0) return 0; // if update was last month (or earlier) int months = today.monthOfYear().getMaximumValue() - today.monthOfYear().getMinimumValue(); // yeah, 12, but just to be 100% correct :-) int curMonth = (today.getYear()

How to get a DateDiff-Value in milliseconds in VBA (Excel)?

大兔子大兔子 提交于 2019-11-27 05:46:38
问题 I need to calculate the difference between two timestamps in milliseconds. Unfortunately, the DateDiff-function of VBA does not offer this precision. Are there any workarounds? 回答1: You could use the method described here as follows:- Create a new class module called StopWatch Put the following code in the StopWatch class module: Private mlngStart As Long Private Declare Function GetTickCount Lib "kernel32" () As Long Public Sub StartTimer() mlngStart = GetTickCount End Sub Public Function

Python: Difference of 2 datetimes in months [duplicate]

烂漫一生 提交于 2019-11-27 05:35:24
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Best way to find the months between two dates (in python) I would like to know how I can have the exact number of months for this difference: date1 = datetime.strptime(str('2011-08-15 12:00:00'), '%Y-%m-%d %H:%M:%S') date2 = datetime.strptime(str('2012-02-15'), '%Y-%m-%d') date2-date1 results in datetime.timedelta(183, 43200) I would like to know the exact number of months, in this case it should return 5 and

SQLite: express the difference as days, hours, minutes between two given dates

空扰寡人 提交于 2019-11-27 03:30:05
问题 I am trying to express the difference of two given dates in days, hours, and minutes (like 1 day, 6 hours, 17 minutes.) as SQLite query output. I have entryin and entryout as datetime fields in a SQLitedatabase. I tried all combinations of julianday and strftime but still running into rough weather. I tried strftime('%d %H:%M', julianday(entryout)-julianday(entryin)) . For a row the values are 2011-11-10 11:46 , and 2011-11-09 09:00 . but the output is 25 14:46 instead of 01 02:46 . Can some