Activity Date without Time - updates time on submission

Created on 3 December 2024, 7 months ago
Updated 16 June 2025, 18 days ago

1.0 Problem/Motivation

Case:

We are loading an activity (activity1=x) onto a form then submitting the form. In this case the date is used to populate additional fields on additional activities that are created.

During testing we noticed that loading the activity with the datetime but field set with no time component sets the time to the current time on submission - even if you don't change the activity date.

2.0 Detailed steps to reproduce (embed screenshots)

Create a Webform,
Enable CiviCRM processing
Add one contact - firstname,lastname (as per default)
Add one activity - add the Activity Date field.
Save
Head to the build screen edit the Activity Date field - set time component to none.
Save
You should have something like the below.

Submit form with date set to something other than today to make it clear what is happening.
Find activity id in results. Note the date and time.
View form with ?activity1=[aid] where aid is the activity id from your submission.
Note it shows the submitted date as displayed in CiviCRM.
Submit the form (Make no changes)
View the activity in CiviCRM - note that the activity time has changed (but date is constant).

civicrm_1_contact_1_fieldset_fieldset:
  '#type': fieldset
  '#title': 'Contact 1'
  '#form_key': civicrm_1_contact_1_fieldset_fieldset
  civicrm_1_contact_1_contact_existing:
    '#type': civicrm_contact
    '#search_prompt': '- Choose existing -'
    '#widget': hidden
    '#form_key': civicrm_1_contact_1_contact_existing
    '#allow_create': 1
    '#none_prompt': '+ Create new +'
    '#default': user
    '#contact_type': individual
    '#parent': civicrm_1_contact_1_fieldset_fieldset
    '#extra': {  }
    '#title': 'Existing Contact'
  civicrm_1_contact_1_contact_first_name:
    '#type': textfield
    '#counter_type': character
    '#counter_maximum': 64
    '#counter_maximum_message': ' '
    '#contact_type': individual
    '#form_key': civicrm_1_contact_1_contact_first_name
    '#extra':
      width: 20
    '#parent': civicrm_1_contact_1_fieldset_fieldset
    '#title': 'First Name'
  civicrm_1_contact_1_contact_last_name:
    '#type': textfield
    '#counter_type': character
    '#counter_maximum': 64
    '#counter_maximum_message': ' '
    '#contact_type': individual
    '#form_key': civicrm_1_contact_1_contact_last_name
    '#extra':
      width: 20
    '#parent': civicrm_1_contact_1_fieldset_fieldset
    '#title': 'Last Name'
civicrm_1_activity_1_fieldset_fieldset:
  '#type': fieldset
  '#title': Activity
  '#form_key': civicrm_1_activity_1_fieldset_fieldset
  civicrm_1_activity_1_activity_activity_date_time:
    '#type': datetime
    '#title': 'Activity Date'
    '#default_value': now
    '#date_time_element': none
    '#form_key': civicrm_1_activity_1_activity_activity_date_time
    '#parent': civicrm_1_activity_1_fieldset_fieldset
    '#extra': {  }

3.0 Proposed resolution

Either:
A) Note this on this ticket. Close and hope it never causes a problem.
B) Add a warning somewhere relevant - probably on the screen where you remove the time component.
C) Should we be able to not set a time component? Probably
D) Do lots of work and ensure we don't update the date with a new time if the time wasn't set on the form.

πŸ› Bug report
Status

Active

Version

6.0

Component

CiviCRM Data Handling

Created by

πŸ‡³πŸ‡ΏNew Zealand luke.stewart

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @luke.stewart
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡¦Ukraine yakim

    This issue originates in Drupal core, not in Webform CiviCRM. It is a known bug tracked in [Drupal core issue #3339005]( https://www.drupal.org/project/drupal/issues/3339005 πŸ› Datetime element with #date_time_element=none adds current time Active ): when a datetime element is configured with `#date_time_element = 'none'`, Drupal still appends the current time on form submission, even though the time input is hidden. This results in unexpected time values (e.g., "2025-01-01 14:22:00") being saved when only a date was intended.

    Webform CiviCRM simply uses Drupal's datetime elements, which rely internally on DrupalDateTime β€” a wrapper around PHP's native DateTime class. When no time is explicitly set, PHP defaults the time component to the current time, which is then preserved in the value passed to CiviCRM.

    Fixing this at the module level would require overriding core behavior and altering how PHP handles date values β€” something that’s not only against Drupal best practices but also technically unreliable and unsustainable.

    Until Drupal core resolves [issue #3339005]( https://www.drupal.org/project/drupal/issues/3339005 πŸ› Datetime element with #date_time_element=none adds current time Active ), this problem can't be properly addressed at the module level. Once the core bug is addressed, Webform CiviCRM will automatically function correctly for date-only fields.

  • πŸ‡¨πŸ‡¦Canada karing πŸ‡¨πŸ‡¦
Production build 0.71.5 2024