Skip to main content

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
Filter by
Sorted by
Tagged with
558 votes
28 answers
576k views

Iterating through a range of dates in Python

I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list ...
ShawnMilo's user avatar
  • 6,105
377 votes
8 answers
517k views

How do I filter query objects by date range in Django?

I've got a field in one model like: class Sample(models.Model): date = fields.DateField(auto_now=False) Now, I need to filter the objects by a date range. How do I filter all the objects that ...
user469652's user avatar
  • 50.5k
307 votes
34 answers
426k views

Javascript - get array of dates between 2 dates

var range = getDates(new Date(), new Date().addDays(7)); I'd like "range" to be an array of date objects, one for each day between the two dates. The trick is that it should handle month and year ...
Scott Klarenbach's user avatar
297 votes
25 answers
346k views

PHP: Return all dates between two dates in an array [duplicate]

Expected Input: getDatesFromRange( '2010-10-01', '2010-10-05' ); Expected Output: Array( '2010-10-01', '2010-10-02', '2010-10-03', '2010-10-04', '2010-10-05' )
HyderA's user avatar
  • 21.1k
192 votes
12 answers
219k views

Loop through a date range with JavaScript

Given two Date() objects, where one is less than the other, how do I loop every day between the dates? for(loopDate = startDate; loopDate < endDate; loopDate += 1) { } Would this sort of loop ...
Tom Gullen's user avatar
  • 62.3k
117 votes
2 answers
113k views

Pandas date_range to generate monthly data at beginning of the month

I'm trying to generate a date range of monthly data where the day is always at the beginning of the month: pd.date_range(start='1/1/1980', end='11/1/1991', freq='M') This generates 1/31/1980, 2/29/...
Bunny_Ross's user avatar
  • 1,448
108 votes
10 answers
70k views

Efficient date range overlap calculation?

I have two date ranges where each range is determined by a start and end date (obviously, datetime.date instances). The two ranges can overlap or not. I need the number of days of the overlap. Of ...
user avatar
98 votes
4 answers
107k views

Merge pandas dataframes where one value is between two others [duplicate]

I need to merge two pandas dataframes on an identifier and a condition where a date in one dataframe is between two dates in the other dataframe. Dataframe A has a date ("fdate") and an ID ("cusip"): ...
itzy's user avatar
  • 11.6k
97 votes
7 answers
184k views

How to know if a DateTime is between a DateRange in C#

I need to know if a Date is between a DateRange. I have three dates: // The date range DateTime startDate; DateTime endDate; DateTime dateToCheck; The easy solution is doing a comparison, but is ...
Daniel Peñalba's user avatar
96 votes
10 answers
158k views

Python generating a list of dates between two dates

I want to generate a list of dates between two dates and store them in a list in string format. This list is useful to compare with other dates I have. My code is given below: from datetime import ...
Mainland's user avatar
  • 4,514
91 votes
10 answers
157k views

How to check if a date is in a given range?

If you have a $start_date and $end_date, how can you check if a date given by the user falls within that range? e.g. $start_date = '2009-06-17'; $end_date = '2009-09-05'; $date_from_user = '2009-...
meleyal's user avatar
  • 32.9k
74 votes
5 answers
41k views

Should I make a DateRange object?

A few of my domain objects contain date ranges as a pair of start and end date properties: public class Period { public DateTime EffectiveDate { get; set; } public DateTime ThroughDate { get; set;...
quentin-starin's user avatar
65 votes
6 answers
99k views

Fetching rows added last hour

I keep a record of logins in a table. I have columns for id, ip, date and time. From that record of logins I wanna fetch logins made only in the last hour. I'm sweeping through the MySQL docs on ...
Michael Grons's user avatar
56 votes
5 answers
155k views

PostgreSQL- Filter a date range

I'm a SQL developer and spend most of my time in MSSQL. I'm looking for a better way to filter a "Timestamp without timezone" field in a PostgreSQL DB. I'm using: Where DateField >= '2010-01-...
Rob S's user avatar
  • 708
44 votes
2 answers
12k views

Is there any kind of standard for representing date ranges?

ISO 8601 represents a date as YYYY-MM-DD. It doesn't seem to offer any recommendation on how to represent a date range, for example: 2013-01-01 => 2013-06-31 Does ISO 8601, or another standard, ...
BenMorel's user avatar
  • 35.9k
39 votes
3 answers
109k views

Grep inside all files created within date range

I am on the Ubuntu OS. I want to grep a word (say XYZ) inside all log files which are created within date range 28-may-2012 to 30-may-2012. How do I do that?
Vijayendra Bapte's user avatar
35 votes
6 answers
127k views

SQL join against date ranges?

Consider two tables: Transactions, with amounts in a foreign currency: Date Amount ========= ======= 1/2/2009 1500 2/4/2009 2300 3/15/2009 300 4/17/2009 2200 etc. ...
Herb Caudill's user avatar
  • 49.8k
34 votes
3 answers
77k views

Subsetting data.table set by date range in R

I have a large dataset in data.table that I'd like to subset by a date range. My data set looks like this: testset <- data.table(date=as.Date(c("2013-07-02","2013-08-03","2013-09-04", ...
black_sheep07's user avatar
33 votes
2 answers
18k views

How Do I Loop Through a Date Range in Reverse?

I have a date range that I would like to be able to loop through in reverse. Give the following, how would I accomplish this, the standard Range operator doesn't seem t be working properly. >> ...
Russ Bradberry's user avatar
33 votes
4 answers
37k views

How to create a pandas DatetimeIndex with year as frequency?

Using the pandas.date_range(startdate, periods=n, freq=f) function you can create a range of pandas Timestamp objects where the freq optional paramter denotes the frequency (second, minute, hour, day.....
imrek's user avatar
  • 3,000
26 votes
4 answers
146k views

ElasticSearch date range

I have the following query: { "query": { "query_string": { "query": "searchTerm", "default_operator": "AND" } }, "facets": { "counts": { "...
Crista23's user avatar
  • 3,233
22 votes
2 answers
13k views

Generating a report by date range in rails

How would you go about producing reports by user selected date ranges in a rails app? What are the best date range pickers? edit in response to patrick : I am looking for a bit of both widget and ...
srboisvert's user avatar
  • 12.7k
21 votes
2 answers
34k views

Find overlapping date ranges in PostgreSQL

Is this correct? SELECT * FROM contract JOIN team USING (name_team) JOIN player USING(name_player) WHERE name_team = ? AND DATE_PART('YEAR',date_join)>= ? AND DATE_PART('YEAR',...
aocferreira's user avatar
21 votes
2 answers
38k views

Aggregate $group for multiple date ranges

In my aggregate, each document in the stream will have a date on it. I need to sum some values over date ranges.. My documents look like: { value: 3, date: [SoME TIME STAMP] }, { value: 4, date: [...
Zhen Liu's user avatar
  • 7,848
21 votes
2 answers
12k views

R Shiny: dateRangeInput for month and year only

Is there a way to hack or create a dateRangeInput() selector in Shiny so that it selects only month and year (no day) or that it automatically selects the first day of the selected month without ...
TiFr3D's user avatar
  • 549
20 votes
7 answers
114k views

Date range picker on jquery ui datepicker

I created a date range picker using jquery ui where you can use the same inline calendar to make both of your date selections. See my fiddle here: http://jsfiddle.net/kVsbq/4/ JS $(".datepicker")....
Mcestone's user avatar
  • 844
19 votes
11 answers
162k views

MySQL query to select events between start/end date

I have a MySQL table named 'events' that contains event data. The important columns are 'start' and 'end' which contain string (YYYY-MM-DD) to represent when the events starts and ends. I want to get ...
Guicara's user avatar
  • 1,688
19 votes
7 answers
133k views

SQL Server : fetching records between two dates?

In SQL I write a SELECT statement to fetch data between two dates, using between and Ex: select * from xxx where dates between '2012-10-26' and '2012-10-27' But the rows returned are for 26th ...
Ssasidhar's user avatar
  • 475
18 votes
4 answers
19k views

How to handle dates in neo4j

I'm an historian of medieval history and I'm trying to code networks between kings, dukes, popes etc. over a period of time of about 50 years (from 1220 to 1270) in medieval Germany. As I'm not a ...
Andreas Kuczera's user avatar
17 votes
7 answers
36k views

Getting Dates between a range of dates

I need to get all the dates present in the date range using SQL Server 2005
user avatar
17 votes
4 answers
32k views

Date range validation

I want to compare two dates (StartDate and EndDate) and check whether one is before the other. The simplest solution is to just do it on the backing bean and "short-circuit" the method. However this ...
ChrisGeo's user avatar
  • 3,867
16 votes
2 answers
18k views

Check if date is within time range using Joda or standard Java API

I have first time as string '12:00:00' and another '19:00:00'. How to check time portion of the day is within these time values?
EugeneP's user avatar
  • 11.9k
16 votes
3 answers
28k views

Include missing months in Group By query

I think I have a tough one here... :( I am trying to get an order count by month, even when zero. Here's the problem query: SELECT datename(month, OrderDate) as Month, COUNT(OrderNumber) AS Orders ...
Michael Nelson's user avatar
15 votes
3 answers
32k views

Postgres LEFT JOIN with WHERE condition

I need to left join two tables with a where condition: Table time_table id rid start_date end_date 1 2 2017-07-01 00:00:00 2018-11-01 00:00:00 2 5 ...
Syed Asad Abbas Zaidi's user avatar
15 votes
1 answer
11k views

ORACLE SQL Date range intersections

I have a table T1, it contains a NAME value (not unique), and a date range (D1 and D2 which are dates) When NAME are the same, we make a union of the date ranges (e.g. B). But as a result (X), we ...
guigui42's user avatar
  • 2,470
14 votes
6 answers
22k views

C# seconds since specific date

In C# 3.0, how do I get the seconds since 1/1/2010?
craigmoliver's user avatar
  • 6,569
13 votes
1 answer
20k views

How to filter last 5 minutes, date histogram using Elastic search?

using Elasticsearch 1.1.1 I'm trying to build a query of "page" views per second for the last 5 minutes for all accounts (so match all). The mapping is... "xxx-20140526": { "mappings": { "...
user432024's user avatar
  • 4,575
13 votes
4 answers
23k views

How can I group an array of objects by month?

I'm using JavaScript. I have an array that contains data in this format: [ {"USER_NAME":"User1","LAST_SUCCESSFUL_CONNECT":"1373978337642"}, {"USER_NAME":"User2","...
Perspectivus's user avatar
12 votes
2 answers
3k views

MySQL: Matching records that have x consecutive dates available between two dates

Background / Application I have a MySQL database containing a table of rentable properties and a table of bookings for these properties. There is also a search feature for finding available ...
Kris's user avatar
  • 1,094
11 votes
1 answer
17k views

Re-index dataframe by new range of dates

I have a data frame containing a number of observations: date colour orders 2014-10-20 red 7 2014-10-21 red 10 2014-10-20 yellow 3 I would like to re-index the ...
Gianluca's user avatar
  • 6,567
11 votes
4 answers
7k views

Fastest way to split overlapping date ranges

I have date range data in SQL DB table that has these three (only relevant) columns: ID (int identity) RangeFrom (date only) RangeTo (date only) For any given date range, there may be an arbitrary ...
Robert Koritnik's user avatar
10 votes
4 answers
16k views

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 ...
dtheodor's user avatar
  • 5,003
10 votes
3 answers
6k views

Efficiently find overlap of date-time ranges from 2 dataframes

There are some questions out there regarding finding the overlap in date or time ranges (for example). I've used these to solve my problem, but I've ended up with an extremely slow (and not-at-all ...
sacuL's user avatar
  • 50.8k
10 votes
3 answers
2k views

Mark non-contiguous date ranges

Background (Input) The Global Historical Climatology Network has flagged invalid or erroneous data in its collection of weather measurements. After removing these elements, there are swaths of data ...
Dave Jarvis's user avatar
9 votes
6 answers
8k views

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 ...
Michael's user avatar
  • 93
9 votes
5 answers
29k views

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 ...
Vipin Parakkat's user avatar
9 votes
3 answers
17k views

jQuery UI Datepicker - Date range - Highlight days in between

I'm looking for a way of highlighting the days in between the date range of 2 inputs on mouse over. This example is nearly doing what I want to achieve: http://hackingon.net/files/jquery_datepicker/...
Mayko's user avatar
  • 439
9 votes
2 answers
15k views

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 ...
Andrew's user avatar
  • 10k
9 votes
4 answers
10k views

SQL group by frequency within a date range

I have a requirement to write a stored procedure that accepts a start date, end date and a frequency (day, week, month, quarter, year) and outputs a result set based on those parameters. Obviously, ...
Scott's user avatar
  • 13.9k
9 votes
2 answers
11k views

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 ...
Robert Koritnik's user avatar

1
2 3 4 5
33