datediff

Oracle - Best SELECT statement for getting the difference in minutes between two DateTime columns?

瘦欲@ 提交于 2019-11-27 02:40:40
问题 I'm attempting to fulfill a rather difficult reporting request from a client, and I need to find away to get the difference between two DateTime columns in minutes. I've attempted to use trunc and round with various formats and can't seem to come up with a combination that makes sense. Is there an elegant way to do this? If not, is there any way to do this? 回答1: SELECT date1 - date2 FROM some_table returns a difference in days. Multiply by 24 to get a difference in hours and 24*60 to get

Count number of Mondays in a given date range

旧巷老猫 提交于 2019-11-27 01:21:10
Given a date range, I need to know how many Mondays (or Tuesdays, Wednesdays, etc) are in that range. I am currently working in C#. Jon B Try this: static int CountDays(DayOfWeek day, DateTime start, DateTime end) { TimeSpan ts = end - start; // Total duration int count = (int)Math.Floor(ts.TotalDays / 7); // Number of whole weeks int remainder = (int)(ts.TotalDays % 7); // Number of remaining days int sinceLastDay = (int)(end.DayOfWeek - day); // Number of days since last [day] if (sinceLastDay < 0) sinceLastDay += 7; // Adjust for negative days since last [day] // If the days in excess of an

Count days between two dates, excluding weekends (MySQL only)

…衆ロ難τιáo~ 提交于 2019-11-26 23:06:26
I need to calculate the difference (in days) between two dates in MySQL excluding weekends (Saturday and Sunday). That is, the difference in days minus the number of Saturday and Sunday in between. At the moment, I simply count the days using: SELECT DATEDIFF('2012-03-18', '2012-03-01') This return 17 , but I want to exclude weekends, so I want 12 (because the 3rd and 4th, 10th and 11th and 17th are weekends days). I do not know where to start. I know about the WEEKDAY() function and all related ones, but I do not know how to use them in this context. biziclop Illustration: mtwtfSSmtwtfSS

How to compare two dates to find time difference in SQL Server 2005, date manipulation

大兔子大兔子 提交于 2019-11-26 22:02:34
I have two columns: job_start job_end 2011-11-02 12:20:37.247 2011-11-02 13:35:14.613 How would it be possible using T-SQL to find the raw amount of time that has passed between when the job started and when the job ended? I tried this: select (job_end - job_start) from tableA but ended up with this: 1900-01-01 01:14:37.367 James Hill Take a look at the DateDiff() function. -- Syntax -- DATEDIFF ( datepart , startdate , enddate ) -- Example usage SELECT DATEDIFF(DAY, GETDATE(), GETDATE() + 1) AS DayDiff SELECT DATEDIFF(MINUTE, GETDATE(), GETDATE() + 1) AS MinuteDiff SELECT DATEDIFF(SECOND,

Only show hours in MYSQL DATEDIFF

自闭症网瘾萝莉.ら 提交于 2019-11-26 21:05:56
问题 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? 回答1: What about using TIMESTAMPDIFF? SELECT TIMESTAMPDIFF(HOUR, start_time, end_time) as `difference` FROM timeattendance WHERE timeattendance_id = '1484' 回答2

The difference in months between dates in MySQL

天大地大妈咪最大 提交于 2019-11-26 19:42:50
I'm looking to calculate the number of months between 2 date time fields. Is there a better way than getting the unix timestamp and the dividing by 2 592 000 (seconds) and rounding up whithin MySQL? The DATEDIFF function can give you the number of days between two dates. Which is more accurate, since... how do you define a month? (28, 29, 30, or 31 days?) Month-difference between any given two dates: I'm surprised this hasn't been mentioned yet: Have a look at the TIMESTAMPDIFF() function in MySQL. What this allows you to do is pass in two TIMESTAMP or DATETIME values (or even DATE as MySQL

Calculating time difference by ID

流过昼夜 提交于 2019-11-26 18:33:18
问题 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

How do I check the difference, in seconds, between two dates?

夙愿已清 提交于 2019-11-26 15:06:57
There has to be an easier way to do this. I have objects that want to be refreshed every so often, so I want to record when they were created, check against the current timestamp, and refresh as necessary. datetime.datetime has proven to be difficult, and I don't want to dive into the ctime library. Is there anything easier for this sort of thing? if you want to compute differences between two known dates, use total_seconds like this: import datetime as dt a = dt.datetime(2013,12,30,23,59,59) b = dt.datetime(2013,12,31,23,59,59) (b-a).total_seconds() 86400.0 #note that seconds doesn't give you

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

天大地大妈咪最大 提交于 2019-11-26 14:22:36
问题 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

Count days between two dates, excluding weekends (MySQL only)

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 08:36:06
问题 I need to calculate the difference (in days) between two dates in MySQL excluding weekends (Saturday and Sunday). That is, the difference in days minus the number of Saturday and Sunday in between. At the moment, I simply count the days using: SELECT DATEDIFF(\'2012-03-18\', \'2012-03-01\') This return 17 , but I want to exclude weekends, so I want 12 (because the 3rd and 4th, 10th and 11th and 17th are weekends days). I do not know where to start. I know about the WEEKDAY() function and all