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
537
votes
25 answers

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 comprehension. day_count = (end_date - start_date).days +…
ShawnMilo
  • 5,896
  • 3
  • 19
  • 15
371
votes
8 answers

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 have a date between 1-Jan-2011 and 31-Jan-2011?
user469652
  • 48,855
  • 59
  • 128
  • 165
293
votes
25 answers

PHP: Return all dates between two dates in an array

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
  • 20,651
  • 42
  • 112
  • 180
291
votes
33 answers

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 boundaries as well.
Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91
183
votes
12 answers

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 work? But how can I add one day to the loop…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
110
votes
2 answers

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/1980, and so on. Instead, I just want 1/1/1980,…
Bunny_Ross
  • 1,378
  • 2
  • 10
  • 9
107
votes
10 answers

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 course I can pre-fill two sets with all dates within…
user2665694
95
votes
4 answers

Merge pandas dataframes where one value is between two others

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"): I need to merge this with this dataframe B: on…
itzy
  • 11,275
  • 15
  • 63
  • 96
93
votes
7 answers

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 there a smarter way to do this?
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
91
votes
10 answers

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-08-28'; At the moment the dates are strings, would…
meleyal
  • 32,252
  • 24
  • 73
  • 79
82
votes
10 answers

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 date, timedelta sdate = date(2019,3,22) # start…
Mainland
  • 4,110
  • 3
  • 25
  • 56
72
votes
5 answers

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; } } public class Timeline { public DateTime…
quentin-starin
  • 26,121
  • 7
  • 68
  • 86
65
votes
6 answers

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 time and date functions, but I just can't seem to…
Michael Grons
  • 685
  • 1
  • 5
  • 4
51
votes
5 answers

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-01' and DateField < '2012-01-01' But given that I'm…
Rob S
  • 658
  • 1
  • 5
  • 7
40
votes
2 answers

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, give a sensible recommendation for representing date…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
1
2 3
99 100