date-range

Determine contiguous dates in SQL gaps and islands

北慕城南 提交于 2019-12-08 07:04:57
问题 I have a situation where a single patient can receive multiple services. These services can have overlapping dates, and can gaps and islands. I am trying to write a query that will show the contiguous length of time that the patient was receiving some kind of service. Table is as follows: CREATE TABLE #tt (Patient VARCHAR(10), StartDate DATETIME, EndDate DATETIME) INSERT INTO #tt VALUES ('Smith', '2014-04-13', '2014-06-04'), ('Smith', '2014-05-07', '2014-05-08'), ('Smith', '2014-06-21', '2014

Interval (days) in PostgreSQL with two parameters

不打扰是莪最后的温柔 提交于 2019-12-08 05:13:46
问题 In this query: Select * from table where future_date - CURRENT_DATE <= '10'; It returns the interval of 10 days or less. How to add two parameters? Example: Select * from table where future_date - CURRENT_DATE <= '10' AND >= '30'; I already tried: Select * from table where future_date - CURRENT_DATE BETWEEN '10' AND '30' But it doesn't work. 回答1: SELECT * FROM mytable WHERE future_date BETWEEN CURRENT_DATE + '10 days'::INTERVAL AND CURRENT_DATE + '30 days'::INTERVAL 回答2: Explanation Your

calculate price between given dates in multiple ranges

孤街浪徒 提交于 2019-12-08 04:37:24
问题 Hi the following code works well when used over two or more ranges but not when the start date and end date are in the same range. When the start date and end date are in the same range the totalprice returns an extra day. Hence the totalprice for one night is doubled. Here is the mysql table; CREATE TABLE rooms ( Hotel_id INT, Room_id INT, Room_type VARCHAR(20), Start_date DATE, End_date DATE, Price INT ); INSERT INTO rooms VALUES ( 13 , 2 , 'standard' , '2012-08-01' , '2012-08-15' , 7000),

How do I create a period date range from a mysql table grouping every common sequence of value in a column

天大地大妈咪最大 提交于 2019-12-08 04:36:13
问题 My goal is to return a start and end date having same value in a column. Here is my table. The (*) have been marked to give you the idea of how I want to get "EndDate" for every similar sequence value of A & B columns ID | DayDate | A | B ----------------------------------------------- 1 | 2010/07/1 | 200 | 300 2 | 2010/07/2 | 200 | 300 * 3 | 2010/07/3 | 150 | 250 4 | 2010/07/4 | 150 | 250 * 8 | 2010/07/5 | 150 | 350 * 9 | 2010/07/6 | 200 | 300 10 | 2010/07/7 | 200 | 300 * 11 | 2010/07/8 |

SQL Query - gather data based on date range - possible variable number of columns

眉间皱痕 提交于 2019-12-08 03:33:07
问题 please forgive my inexperience, I hope this isn't too dumb of a question, I'm stuck and have no where else to turn. I'll keep it to the point: I'm trying to gather payroll data with the results like so: The issue I have is the variable number of columns . I will be given a date range and are required to return an attendance record for each day in the given range, or a null value if no data is present. I'm using WebAPI as middle tier so I have the ability to perform further data manipulation

Date range restriction with JavaScript

梦想的初衷 提交于 2019-12-07 11:38:35
问题 There are two input fields of type text to write a start date and end date in format mm/dd/yyy. I need a JavaScript function to check that the date range interval between those entered dates does not exceed 14 days. And the maximum date should be the current date. Is there a plugin or a fast solution for this? I tried to use the jQuery UI datepicker which would work fine, but I have a custom GetElementByClassName function which conflicts with jQuery. Thank you. 回答1: The following snippets

Select a date range from a timestamp column

不打扰是莪最后的温柔 提交于 2019-12-07 07:07:20
问题 Currently my table has a column to store date and time. The data type of that column is timestamp without time zone . So it has values in the format '2011-09-13 11:03:44.537' . I need to retrieve rows with respect to the date. If I use: select * from table where mdate >= '2011-09-13 11:03:44.537' and mdate <= '2011-09-12 11:03:44.537' it will provide the values which are in between '2011-09-13 11:03:44.537' and '2011-09-12 11:03:44.537'. But if I am going with: select * from table where mdate

SQL Query - gather data based on date range - possible variable number of columns

可紊 提交于 2019-12-06 16:06:49
please forgive my inexperience, I hope this isn't too dumb of a question, I'm stuck and have no where else to turn. I'll keep it to the point: I'm trying to gather payroll data with the results like so: The issue I have is the variable number of columns . I will be given a date range and are required to return an attendance record for each day in the given range, or a null value if no data is present. I'm using WebAPI as middle tier so I have the ability to perform further data manipulation to achieve this result. My tables are as follows: I can't be the first person who needs this done, any

calculate price between given dates in multiple ranges

自闭症网瘾萝莉.ら 提交于 2019-12-06 15:19:32
Hi the following code works well when used over two or more ranges but not when the start date and end date are in the same range. When the start date and end date are in the same range the totalprice returns an extra day. Hence the totalprice for one night is doubled. Here is the mysql table; CREATE TABLE rooms ( Hotel_id INT, Room_id INT, Room_type VARCHAR(20), Start_date DATE, End_date DATE, Price INT ); INSERT INTO rooms VALUES ( 13 , 2 , 'standard' , '2012-08-01' , '2012-08-15' , 7000), ( 13 , 2 , 'standard' , '2012-08-16' , '2012-08-31' , 7500), ( 13 , 2 , 'standard' , '2012-09-01' ,

Compare multiple date ranges

天涯浪子 提交于 2019-12-06 14:34:30
问题 I am using iReport 3.0.0, PostgreSQL 9.1. For a report I need to compare date ranges from invoices with date ranges in filters and print for every invoice code if a filter range is covered , partially covered , etc. To complicate things, there can be multiple date ranges per invoice code. Table Invoices ID Code StartDate EndDate 1 111 1.5.2012 31.5.2012 2 111 1.7.2012 20.7.2012 3 111 25.7.2012 31.7.2012 4 222 1.4.2012 15.4.2012 5 222 18.4.2012 30.4.2012 Examples Filter: 1.5.2012. - 5.6.2012.