Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2017 at 15:09 UTC
Updated:
13 Oct 2025 at 00:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
lendudeDiscussion on this on several issues:
#2832652: Date between filter is filtering wrong
#2832058: Add time to views date filter
#2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter
And that (of course) all leads back to #2369119: Fatal error when trying to save a View with grouped filters using other than string values.
The problem is that we use the start of the day for both start and end date. To get a result that is more in line with expectations we should probably use 00:00:00 for the start date and 23:59:59 for the end date when generating a timestamp.
All the referenced issues are working on fixes that at least make it clear to end users that the start of day is used or to make the used time configurable.
Not sure if we should look into modifying the default used time or just see if the other issues manage to make it configurable.
Comment #3
mpdonadioThe offending code is in filter/Date:
If you enter a date w/o a time portion, then strtotime uses sets it to 00:00:00 (unlike what \DateTime does). The problem figuring out user intent here with a function that will try to handle any input.
#2627512: Datetime Views plugins don't support timezones is also related here, and that does some major rework on some of the low level date handling.
#2647292: Date/time Views filter tries strotime() relative to Unix epoch is also related.
Comment #9
jcalais commentedFrom steps to reproduce:
> Now chose twice the same day
I would argue that this bug affects all date exposed filters using the between operator, because using strtotime will always have the end date stamp for the absolute beginning of the day (00:00), so no items from the end day will ever be included.
I do understand the logical argument that a views filter between the dates 2019-01-01 and 2019-01-02 should only include items from 2019-01-01, since logically 2019-01-02 starts at 00:00. However our users won't see it that way.
The "offending" line is in core/modules/views/src/Plugin/views/filter/Date.php#170
$b = intval(strtotime($this->value['max'], 0));
I will add a patch to change this behavior if your users agree with ours. I don't expect this to be accepted, since this is probably a much bigger discussion, but we need a quick(ish) fix. Perhaps we need a checkbox with the text "include end date in the result set", but that also sounds a bit over-engineered.
Comment #10
jcalais commentedAdded simple fix to the max date for including it in the max date.
Comment #11
feyp commentedThis has a patch, but still needs tests. Setting to "Needs work".
Comment #12
lendudeA possible problem I see with #10 is that by adding a full day it will also add results that start at 'NextDay 00:00:00', so we would have to take one second off.
Which in turn could lead to events starting at 'ThisDay 23:59:59' on a day we have a leap second falling off (not likely I know :D)
Edit: Hmm maybe BETWEEN handles that right, not sure. Needs tests.....
Comment #15
anas_maw commentedI think this should be handled in strtotime function, as this patch
Comment #17
vakulrai commentedRerolled for 9.2.x , with some changes to tests based on new implementation from #15.
Thanks.
Comment #19
alansaunders92 commentedWhen I tried to apply the patch from comment 17 on Drupal 9.2.4, the changes made to the test file FilterDateTest.php for me failed to apply. I have re rolled the patch and that seems to have done the job for me.
Comment #20
lendudeShouldn't we only do this when there is no time component on the passed value?
Unrelated change, so we should take that out
And some more test coverage of edge cases would be nice.
Comment #25
johnvThe patch still is valid on D11.1
The problem occurs and is solved in both cases: with Date filter 'date' option and with 'offset' option. Updating summary.
A test is added, but #20 is still relevant.
Comment #28
niranjan_panem commentedchecked the issue, still exists. Created a patch below is that it contains current timestamp added to offsets to resolve the offset issue.
Comment #30
riyas_nr commentedMR in #28 didn’t fix the actual issue where, if the same date is provided in the filter, it won’t filter the full day as expected.
As the problem lies in:
offsettype with identical min and max (e.g., +1 day):datetype, with identical min and max (e.g., 2025-03-03):$aand$bwill be same2025-03-03 00:00:00with no resultSolution:
OffsetType:min === maxand the offset is a whole day (% 86400 === 0), adjust max toend of day(+86399seconds).+1 day 4 hours).DateType:maxhas no time (H:i:s = 00:00:00), adjustmaxto23:59:59for full-day matchingAddressed time component check and added test for edge cases mentioned in #20. Moving to NR.
Comment #31
smustgrave commentedComment #32
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #33
riyas_nr commentedMoving to NR.
Comment #34
riyas_nr commented@Lendude I’ve updated the logic so that the “end of day” adjustment is applied only when the min and max values are on the same calendar date.
This fixes the issue in existing Views where the “until” filter was returning an extra day’s results.
However, this change introduces a new scenario:
min date = 2025-08-08andmax date = 2025-08-08will now return the same results asmin date = 2025-08-08andmax date = 2025-08-09, since both cases include the entire day of 2025-08-08.Another solution I'm thinking for the issue is to remove this logic entirely and simply validate that the max value must always be greater than the min value, either by time offset or by date, to avoid identical results for different ranges.
What are your thoughts on this?
Comment #35
smustgrave commentedThink validating max is greater then min makes sense here.