Questions tagged [date-range]

Date-range refers to a range of dates, i.e. a period of time between a start date and an end date.

Date-range refers to a range of dates, i.e. a period of time between a start date and an end date.

Date range is commonly used:

  • as search criterion for any date related data,
  • when operating on data referring to periods of time.
1608 questions
9
votes
2 answers

Querying with nHibernate where todays date is between publishDate and Expiry date

I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime The expiry date can be null so I need to allow for that. I found a couple of…
Andrew
  • 9,967
  • 10
  • 64
  • 103
9
votes
5 answers

Efficient way of storing date ranges

I need to store simple data - suppose I have some products with codes as a primary key, some properties and validity ranges. So data could look like this: Products code value begin_date end_date 10905 13 2005-01-01 2016-12-31 10905 …
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
9
votes
2 answers

Prevent inserting overlapping date ranges using a SQL trigger

I have a table that simplified looks like this: create table Test ( ValidFrom date not null, ValidTo date not null, check (ValidTo > ValidFrom) ) I would like to write a trigger that prevents inserting values that overlap an existing date range.…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
9
votes
4 answers

How to create a new date range type with included upper bound in Postgres?

Postgres comes with a nice feature called Range Types that provides useful range functionality (overlaps, contains, etc). I am looking to use the daterange type, however I think the type was implemented with an awkward choice: the upper bound of the…
dtheodor
  • 4,894
  • 3
  • 22
  • 27
9
votes
6 answers

SQL CHECK constraint to prevent date overlap

I have a table that describes which software versions were installed on a machine at various times: machine_id::integer, version::text, datefrom::timestamp, dateto::timestamp I'd like to do a constraint to ensure that no date ranges overlap, i.e.…
Michael
  • 93
  • 1
  • 3
8
votes
4 answers

How to detect if dates are consecutive in Python?

I have an access table with a 'Date' field. it has random dates for each record. I've built a script to append all the records into a list and then set the list to filter out only the unique values: dateList = [] # cursor search through each record…
Mike
  • 4,099
  • 17
  • 61
  • 83
8
votes
6 answers

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

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…
SoulieBaby
  • 5,405
  • 25
  • 95
  • 145
8
votes
2 answers

Month jumping on date selection using react-date-range

I'm using DateRangePicker from react-date-range in a next.js project. You can see the expected behavior on their demo page: if you select any date from the month on the right, the months stay in place. Here's a video. But in my project, the month…
Barnee
  • 3,212
  • 8
  • 41
  • 53
8
votes
2 answers

Create a row for every month between 2 dates in PostgreSQL

I need to create a row for every month (result should be first day of the month) between 2 dates for each person in my table. For example, if I have the following data in my source table: rowID | person | startdate | enddate 1 | 12345 …
BDad
  • 95
  • 1
  • 5
8
votes
4 answers

URL convention for date range

What would be the accepted convention for displaying a date range in a friendly URL? For example, in a time tracking application. Instead of using the database's primary key for a specific pay period in the URL, I would like to use something more…
Jason B
  • 85
  • 1
  • 1
  • 4
8
votes
2 answers

Remove minDate/maxDate limits in jQuery UI Datepicker

A simple issue, but I can't seem to find the answer. I've limited the date range in jQuery Datepicker: $( "#MyDatepicker" ).datepicker( "option", "minDate", new Date()) Is there a way to remove all restrictions for date range?
Earl Grey
  • 95
  • 1
  • 1
  • 4
8
votes
5 answers

Postgresql select between month range

I have table with one of the columns as date in 'YYYY-MM-DD' format. Can I use select to get all data in a monthly range? Say I want all the data from 2012-01-xx to 2013-04-xx. So I am basically looking for a SQL query like the one given…
Vipin Parakkat
  • 636
  • 2
  • 6
  • 12
7
votes
5 answers

django aggregation to lower resolution using grouping by a date range

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() …
kraiz
  • 2,178
  • 1
  • 22
  • 22
7
votes
2 answers

Ruby's range step method causes very slow execution?

I've got this block of code: date_counter = Time.mktime(2011,01,01,00,00,00,"+05:00") @weeks = Array.new (date_counter..Time.now).step(1.week) do |week| logger.debug "WEEK: " + week.inspect @weeks << week end Technically, the code works,…
Aaron Vegh
  • 5,217
  • 7
  • 48
  • 75
7
votes
1 answer

Postgres - split TSTZRANGE in two columns

I'm using PostgreSQL 9.4 I have column in a table named timerange and want to write a SELECT query which will return time range in two separate columns time_start and time_end. I tried to handle this like an array but it doesn't work: select *,…
veich
  • 501
  • 1
  • 6
  • 15