Problem/Motivation
Given a date field, with the 'Date only' setting and 'Current date' as the default, the current date can be wrong for the configured time zone. It works as expected if the field is set to 'Date and time'
Screenshot of two date fields, one with Date only and one with Date and time, using Current date as the default, with timezone set to Los Angeles:

Same node, with the timezone set to UTC:

Steps to reproduce
Not sure whether it matters what time this is tested, but my test was done at 7:33pm PST.
- Install Drupal
- Add a Date field to the article content type, with 'Date only', and the default set to 'Current date'
- Add another date field with 'Date and time' and the default set to 'Current date'
- Set the site timezone to Los Angeles
- Create a node, see that the date is different between the fields
- Set the timezone to UTC
- See that the date is correct
Proposed resolution
Figure out why the default date is wrong and fix.
Remaining tasks
- Find the cause of this issue
- Write a patch with tests
- Review
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Original report by charlie1volley
Hi,
New to Drupal. I searched and read about various date/time issues but I'm sure if this is a similar issue to any of them or if/what to do about it?
What are the steps required to reproduce the bug?
Create date field in content type and default to 'current date'. Select settings 'date only'. When I create content (for example right now its 7/23/2019 9PM PST) it shows 7/24/2019. If I change the field setting to 'date and time' though it returns the correct date and time.
What behavior were you expecting? The date to be today in PST.
What happened instead? Incorrect date, a day ahead.
Thanks for any help you can provide on this...
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3069854-11.patch | 974 bytes | wombatbuddy |
| #5 | Screen Shot 2020-11-20 at 1.34.51 pm.png | 8.05 KB | pameeela |
| #5 | Screen Shot 2020-11-20 at 1.35.43 pm.png | 7.9 KB | pameeela |
Comments
Comment #2
charlie1volley commentedSorry, should have added that config time zone is set to 'Los Angeles' and I tried checking and unchecking the 'users may set their own time zone' box.
Comment #5
pameeela commentedUpdated IS with steps to reproduce. I suspect this may have something to do with the 'Date only' getting a time set of 12:00?
Comment #6
pameeela commentedComment #7
adityasingh commentedThis I believe is as per expected behaviour as can be seen in the following documents in
core/modules/datetime/src/DateTimeComputed.phpfile.and this link
https://www.php.net/manual/en/datetime.createfromformat.php#110385
Comment #8
atul4drupal commentedThanks @pameeela & @adityasingh you have it rightly pointed, the issue is because by default time is set to 12:00:00
File: core/lib/Drupal/Component/Datetime/DateTimePlus.php
@line: 711
This is actually causing the issue to occur for few hours as long the date differs between local time zone (if other that UTC) and UTC.
One possible solution might be to adjust the default fallback time according to sites local time zone i.e get +/- in time from UTC time for current timezone and accordingly set the default time for the date field.
Feel free to share suggestions.
Comment #9
atul4drupal commentedMistakenly had it closed...
Comment #10
scott.whittaker commentedJust ran into this one myself. It seems the most logical solution to me would be to set the datetime created to midnight in the current timezone. What is the point of standardising the time portion when it makes the date portion incorrect, and that's the only portion we actually care about.
It's hard to see how this buggy behaviour could be considered "works as designed".
Comment #11
wombatbuddy commentedIn case of the 'Date only' setting the 'UTC' is used instead of user's timezone. It looks like this is the reason of the issue.
Comment #12
wombatbuddy commentedComment #14
edmonkey commentedComment #15
pameeela commentedDuplicate of #2993165: Date Only field shows incorrect default value when UTC date is different than user's date and that was created earlier and has more activity, so closing this one.
Comment #16
wombatbuddy commented@pameeela, Is it make sense to transfer the patch from this issue there? It seems is different from those offered in that issue.
Comment #17
pameeela commented@wombatbuddy, yes that's a good idea, a new patch might just revive the issue :) It is failing though, not sure whether the fails are random or not, but if not would be good to address them before you transfer it. Thanks!