date-range

PostgreSQL daterange not using index correctly

情到浓时终转凉″ 提交于 2019-12-01 21:27:16
I have a simple table which has a user_birthday field with a type of date (which can be NULL value) CREATE TABLE users ( user_id bigserial NOT NULL, user_email text NOT NULL, user_password text, user_first_name text NOT NULL, user_middle_name text, user_last_name text NOT NULL, user_birthday date, CONSTRAINT pk_users PRIMARY KEY (user_id) ) There's an index (btree) defined on that field, with the rule of NOT user_birthday IS NULL. CREATE INDEX ix_users_birthday ON users USING btree (user_birthday) WHERE NOT user_birthday IS NULL; Trying to follow up on another idea, I've added the extension

PHP combine two seperate conflicting date ranges into unique pairs

百般思念 提交于 2019-12-01 20:58:09
Set one: 2014-04-05 To 2014-06-27 2014-06-28 To 2014-10-19 Set two: 2014-04-05 To 2014-05-02 2014-05-03 To 2014-05-31 2014-06-01 To 2014-10-19 What I need this to output is: 2014-04-05 To 2014-05-02 2014-05-03 To 2014-05-31 2014-06-01 To 2014-06-27 2014-06-28 To 2014-10-19 I attempted to use a function to check for overlaps as such: !($lhs['RecordOnset'] > $rhs['RecordOffset'] || $lhs['RecordOffset'] < $rhs['RecordOnset']) And used a for loop to check for the overlap: for($i = 1; $i < sizeof($arr1); $i++) { for($j = 1; $j < sizeof($arr2); $j++) { $record = $arr1[$i]; if($result = $this-

datatables date filter

时光毁灭记忆、已成空白 提交于 2019-12-01 18:16:31
I have one Date column, formatted '17/03/2012'. I would like to be able select a start and end date and if the 1 date column above is within this date range it will filter the column. Below is the code im using: Start Date: <input type="text" id="dateStart" name="dateStart" size="30"> End Date: <input type="text" id="dateend" name="dateend" size="30"> <script type="text/javascript" charset="utf-8"> $.fn.dataTableExt.afnFiltering.push( function( oSettings, aData, iDataIndex ) { var iFini = document.getElementById('dateStart').value; var iFfin = document.getElementById('dateend').value; var

Bokeh patches plot with dates as x-axis shifts the ticks one to the right

别等时光非礼了梦想. 提交于 2019-12-01 06:49:11
I'm trying to adapt the brewer example ( http://bokeh.pydata.org/en/latest/docs/gallery/brewer.html ) to my needs. One of the things I'd like is to have dates at the x-axis. I did the following: timesteps = [str(x.date()) for x in pd.date_range('1950-01-01', '1951-07-01', freq='MS')] p = figure(x_range=FactorRange(factors=timesteps), y_range=(0, 800)) p.xaxis.major_label_orientation = np.pi/4 as an adaptation of the previous line p = figure(x_range=(0, 19), y_range=(0, 800)) The dates are displayed, but the first date 1950-01-01 sits at x=1. How can I shift it to x=0? The first real data

Declarative approach to constrain data ranges in table

给你一囗甜甜゛ 提交于 2019-12-01 06:44:44
问题 I would like to learn a declarative approach for a data constraint issue I have had from time to time related to exclusive date ranges. Below is a simplified example. I have items and prices on those items. I want the effective date range of the prices to be mutually exclusive with no overlap. As I understand things with Oracle, user-defined functions are not eligible for use in CONSTRAINT declarations - and I can't even imagine how poorly it would perform if it were allowed. So I require a

SQL DateDiff without weekends and public holidays

我怕爱的太早我们不能终老 提交于 2019-12-01 06:03:42
问题 I am looking for solution how to select number of days between two dates without weekends and public holidays. So far I have this: SELECT evnt.event_id, evnt.date_from, evnt.date_to, DATEDIFF(DD, evnt.date_from, evnt.date_to) - (DATEDIFF(WK, evnt.date_from, evnt.date_to) * 2) - CASE WHEN DATEPART(DW, evnt.date_from) = 1 THEN 1 ELSE 0 END + CASE WHEN DATEPART(DW, evnt.date_to) = 1 THEN 1 ELSE 0 END AS Date_Diff --- COUNT(*) FROM public_holidays AS h WHERE h.date_from BETWEEN evnt.date_from AND

django aggregation to lower resolution using grouping by a date range

你。 提交于 2019-12-01 05:52:12
horrible title, but let me explain: i've got this django model containing a timestamp (date) and the attribute to log - f.e. the number of users consuming some ressource - (value). class Viewers(models.Model): date = models.DateTimeField() value = models.IntegerField() for each 10seconds the table contains the number of users. something like this: | date | value | |------|-------| | t1 | 15 | | t2 | 18 | | t3 | 27 | | t4 | 25 | | .. | .. | | t30 | 38 | | t31 | 36 | | .. | .. | now i want to generate different statistics from this data, each with another resolution. f.e. for a chart of the last

How can I group an array of objects by month?

旧巷老猫 提交于 2019-12-01 03:56:35
I'm using JavaScript. I have an array that contains data in this format: [ {"USER_NAME":"User1","LAST_SUCCESSFUL_CONNECT":"1373978337642"}, {"USER_NAME":"User2","LAST_SUCCESSFUL_CONNECT":"1374515704026"}, {"USER_NAME":"User3","LAST_SUCCESSFUL_CONNECT":"1374749782479"} ] (the numbers above represent UTC date/time in milliseconds. I would like to group (count) the data by month. Something like this: [ {"Month":"January, 2014","User_Count": 2}, {"Month":"February, 2014","User_Count": 1}, ] I could use jQuery if it simplifies matters. This looks like a map reduce problem. The high-level solution

Average stock history table

☆樱花仙子☆ 提交于 2019-11-30 16:23:16
I have a table that tracks changes in stocks through time for some stores and products. The value is the absolute stock, but we only insert a new row when a change in stock occurs. This design was to keep the table small, because it is expected to grow rapidly. This is an example schema and some test data: CREATE TABLE stocks ( id serial NOT NULL, store_id integer NOT NULL, product_id integer NOT NULL, date date NOT NULL, value integer NOT NULL, CONSTRAINT stocks_pkey PRIMARY KEY (id), CONSTRAINT stocks_store_id_product_id_date_key UNIQUE (store_id, product_id, date) ); insert into stocks

How to check if a date is between date1 and date2 using mysql?

二次信任 提交于 2019-11-30 15:37:18
问题 I'm trying to write a query that will check today's date against my table columns date1 and date2 in mysql/php.. This is what I'm after: 'events' table: date1 = start date (XXXX-XX-XX) date2 = end date (XXXX-XX-XX) query: select * from events where 2012-01-18 between date1 and date2 (or equal to date1 and date2) But I'm not sure how to go about it.. any help would be appreciated :) EDIT: Maybe I was unclear.. if todays date = '2012-01-18' I need it to find results if today's date is between