Questions tagged [intervals]

Intervals are used to measure “distance” between values.

Intervals are used to measure “distance” between values.

In the DBMS world interval typically refers to the period between 2 timestamps, many modern RDBMS systems natively supports intervals and operation with them.

More information on the intervals can be found in the wild.

2903 questions
235
votes
9 answers

How do I convert an interval into a number of hours with postgres?

Say I have an interval like 4 days 10:00:00 in postgres. How do I convert that to a number of hours (106 in this case?) Is there a function or should I bite the bullet and do something like extract(days, my_interval) * 24 + extract(hours,…
agnul
  • 12,608
  • 14
  • 63
  • 85
207
votes
5 answers

Postgresql query between date ranges

I am trying to query my postgresql db to return results where a date is in certain month and year. In other words I would like all the values for a month-year. The only way i've been able to do it so far is like this: SELECT user_id FROM user_logs…
John
  • 6,417
  • 9
  • 27
  • 32
130
votes
8 answers

Do something every x minutes in Swift

How can I run a function every minute? In JavaScript I can do something like setInterval, does something similar exist in Swift? Wanted output: Hello World once a minute...
JOSEFtw
  • 9,781
  • 9
  • 49
  • 67
80
votes
5 answers

Using a variable period in an interval in Postgres

I have a relation that maintains monthly historical data. This data is added to the table on the last day of each month. A service I am writing can then be called specifying a month and a number of months prior for which to retrieve the historical…
Belizzle
  • 1,295
  • 3
  • 13
  • 28
74
votes
9 answers

How to join two dataframes for which column values are within a certain range?

Given two dataframes df_1 and df_2, how to join them such that datetime column df_1 is in between start and end in dataframe df_2: print df_1 timestamp A B 0 2016-05-14 10:54:33 0.020228 0.026572 1 2016-05-14 10:54:34 …
DougKruger
  • 4,424
  • 14
  • 41
  • 62
57
votes
11 answers

Show TimePicker with minutes intervals in android

My application show a TimePickerDialog to set a time. I want that the timePickerDialog show the minutes with an interval of 5 minutes. This works fine with this code: private final int TIME_PICKER_INTERVAL=5; private boolean mIgnoreEvent=false; … …
Sergio76
  • 3,835
  • 16
  • 61
  • 88
56
votes
7 answers

How can I use ranges in a switch case statement using JavaScript?

How can I use ranges in a switch case statement using JavaScript? So, instead of writing code for each and every single possibility, I'd like to group them in ranges, For example: switch(myInterval){ case 0-2: //doStuffWithFirstRange(); …
Lave Loos
  • 1,252
  • 1
  • 11
  • 15
52
votes
3 answers

How do you create vectors with specific intervals in R?

I have a question about creating vectors. If I do a <- 1:10, "a" has the values 1,2,3,4,5,6,7,8,9,10. My question is how do you create a vector with specific intervals between its elements. For example, I would like to create a vector that has the…
Luli
  • 573
  • 1
  • 4
  • 4
50
votes
3 answers

Working with INTERVAL and CURDATE in MySQL

I'm building a chart and I want to receive data for each month. Here's my first request which is working: SELECT s.GSP_nom AS nom, timestamp, AVG( v.vote + v.prix ) /2 AS avg FROM votes_serveur AS v INNER JOIN serveur AS s ON v.idServ =…
sf_tristanb
  • 8,725
  • 17
  • 74
  • 118
48
votes
15 answers

C: How to wrap a float to the interval [-pi, pi)

I'm looking for some nice C code that will accomplish effectively: while (deltaPhase >= M_PI) deltaPhase -= M_TWOPI; while (deltaPhase < -M_PI) deltaPhase += M_TWOPI; What are my options?
P i
  • 29,020
  • 36
  • 159
  • 267
47
votes
4 answers

Run a function periodically in Scala

I want to call an arbitrary function every n seconds. Basically I want something identical to SetInterval from Javascript. How can I achieve this in Scala?
src091
  • 2,807
  • 7
  • 44
  • 74
45
votes
9 answers

PHP: How can I determine if a variable has a value that is between two distinct constant values?

How can I determine using PHP code that, for example, I have a variable that has a value between 1 and 10, or between 20 and 40?
Gabriel Meono
  • 990
  • 3
  • 18
  • 48
43
votes
3 answers

Checking whether clearInterval has been called?

Given this code: bob = setInterval(function, 1000); clearInterval(bob); Is there now a way to know if that interval has been cleared? Currently, I keep track of this myself, by unsetting 'bob', but I'm curious if my extra line of code is…
swajak
  • 2,669
  • 3
  • 20
  • 22
43
votes
4 answers

How can I plot data with confidence intervals?

If I have 10 values, each of which has a fitted value F, and an upper and lower confidence interval U and L: set.seed(0815) F <- runif(10, 1, 2) L <- runif(10, 0, 1) U <- runif(10, 2, 3) How can I show these 10 fitted values and their confidence…
Kazo
  • 1,205
  • 3
  • 15
  • 15
42
votes
1 answer

Make a range in postgres

How can I make a range in a select in PostgreSQL? I'd like to have this result: num --- 1 2 3 4 5 6 From a query like: SELECT range(1,6) AS num;
1
2 3
99 100