datepart

SUM of Duration based on the DateTime that needs to be updated in previous Half hour interval

坚强是说给别人听的谎言 提交于 2019-12-10 12:19:55
问题 I searched several questions but that all are not exactly answering my question. Hence raised this question here. I have a table say 'Table' that has has DateTime,ID, Code and Duration are the columns. DateTime will be having data as '2017-12-12 00:30:00','2017-12-12 00:30:37' etc and I need to SUM the duration column based on this Interval date. If DateTime is '2017-12-12 00:30:00' then our query should sum all the data between '2017-12-12 00:00:00' to '2017-12-12 00:30:00' and show it in

SQL Server 2008 select data only between month and year

喜欢而已 提交于 2019-12-08 12:56:38
问题 I would like select data between two date, without day An input example: start month: 9 , start year: 2011 end month: 3, end year: 2012 I think that there are two way to do this. The first is convert start month and start year to date like 2011-09-01 and convert last date to 2012-03-31 , but this requires calculation of the last day of end month. Obtained these date we can use a BEETWEN function for the WHERE clause (but, is the CONVERT function reliable?) The second solution is to use the

Oracle equivalent to SQL Server DATEPART

核能气质少年 提交于 2019-12-06 17:04:07
问题 We need to get the HOUR out of a DATETIME column (expecting values from 0 to 23 to be returned). Is there an Oracle equivalent of the SQL Server DATEPART function? 回答1: SELECT to_number(to_char(sysdate, 'HH24')) FROM DUAL 回答2: An alternative is the EXTRACT function which is an ANSI standard and also works on other DBMS, but it also requires the use of current_timestamp (also ANSI) instead of sysdate SELECT extract(hour from current_timestamp) FROM dual 回答3: I think this is what you are

How to compare two DATE values based only on date part in Oracle?

雨燕双飞 提交于 2019-12-05 16:17:11
问题 I am trying to get counts for last 30 days with the following query - SELECT date_occured, COUNT(*) FROM problem WHERE date_occured >= (CURRENT_DATE - 30) GROUP BY date_occured; //date_occured field is of type DATE. Basically, in my query I am trying to compare only the date part in the condition date_occured >= (CURRENT_DATE - 30) , but it seems to compare the time too. I tried the TRUNC as follows - TRUNC(date_occured) >= TRUNC(CURRENT_DATE - 30) But when run the query it never returns. I

How do you convert the number you get from datepart to the name of the day?

回眸只為那壹抹淺笑 提交于 2019-12-05 04:43:02
Is there a quick one-liner to call datepart in Sql Server and get back the name of the day instead of just the number? select datepart(dw, getdate()); This will return 1-7, with Sunday being 1. I would like 'Sunday' instead of 1. select datename(weekday, getdate()); It actually took me more searching than I thought it would to find this answer. It's funny how you can use a technology for ages and never know about simple functions like this. select datename(dw, getdate()) I'm not sure how localization would work with this function. Getting the name client-side is probably the answer, but it

Oracle equivalent to SQL Server DATEPART

三世轮回 提交于 2019-12-04 22:40:39
We need to get the HOUR out of a DATETIME column (expecting values from 0 to 23 to be returned). Is there an Oracle equivalent of the SQL Server DATEPART function? SELECT to_number(to_char(sysdate, 'HH24')) FROM DUAL An alternative is the EXTRACT function which is an ANSI standard and also works on other DBMS, but it also requires the use of current_timestamp (also ANSI) instead of sysdate SELECT extract(hour from current_timestamp) FROM dual Ranjith M R I think this is what you are looking for select to_char(current_timestamp,'HH24') from dual; for additional ways of using DATEPART kind of

How to compare two DATE values based only on date part in Oracle?

主宰稳场 提交于 2019-12-04 01:39:40
I am trying to get counts for last 30 days with the following query - SELECT date_occured, COUNT(*) FROM problem WHERE date_occured >= (CURRENT_DATE - 30) GROUP BY date_occured; //date_occured field is of type DATE. Basically, in my query I am trying to compare only the date part in the condition date_occured >= (CURRENT_DATE - 30) , but it seems to compare the time too. I tried the TRUNC as follows - TRUNC(date_occured) >= TRUNC(CURRENT_DATE - 30) But when run the query it never returns. I also tried - SELECT date_occured, COUNT(*) FROM problem GROUP BY date_occured HAVING TRUNC(date_occured)

How to properly convert a date into a ISO-8601 Week number format in SQL Server?

混江龙づ霸主 提交于 2019-12-02 00:57:47
ISO-8601 states that week numbers are to be formated as YYYY-W## - observe that the week number should be two digits as 01, 02, ... SELECT cast(DATEPART(YYYY, CreationDate) as varchar) + '-W' + cast(DATEPART(ISO_WEEK, GETDATE())` The problem is that this gives the week number as 1, 2, ... What is the correct way of extracting 2020-W01, ... SELECT cast(DATEPART(YYYY, CreationDate) as varchar) + '-W' + Right('0'+cast(DATEPART(ISO_WEEK,CreationDate) as Varchar),2) The original question text relates to a simple formatting issue of the ISO_WEEK number, but I feel there is a bigger issue here with

SQL Query for retreiving records that fall on the last day of the month

感情迁移 提交于 2019-12-01 13:34:02
I have a table with records from many dates. I would like to perform a query that only returns records that fall on the last day of the date's month. Something like: SELECT * FROM mytable WHERE DATEPART(d, mytable.rdate) = DATEPART(d,DATEADD(m,1,DATEADD(d, -1, mytable.rdate))) Except this doesn't work as the rdate in the right-hand side of the argument should be the last day of it's month for the dateadd to return the correct comparison. Basically is there an concise way to do this comparison? An equivalent for quarter-ends would also be very helpful, but no doubt more complex. EDIT:

SQL Query for retreiving records that fall on the last day of the month

大兔子大兔子 提交于 2019-12-01 10:55:31
问题 I have a table with records from many dates. I would like to perform a query that only returns records that fall on the last day of the date's month. Something like: SELECT * FROM mytable WHERE DATEPART(d, mytable.rdate) = DATEPART(d,DATEADD(m,1,DATEADD(d, -1, mytable.rdate))) Except this doesn't work as the rdate in the right-hand side of the argument should be the last day of it's month for the dateadd to return the correct comparison. Basically is there an concise way to do this comparison