0

I am working on an already existing site that has content.

There is a content type with field date and time. I need to remove the time component and just be Date only without deleting any content along the way. If the time data is lost, that is fine.

Can I simply delete the field and recreate it with date only? Or will that delete the existing data?

enter image description here

2
  • will that delete the existing data? yep, any time you delete a field, all the data is deleted as well.
    – No Sssweat
    Oct 21 '20 at 6:17
  • 1
    This maybe can be done with config. Export current config, change as desired, reimport. Otherwise create another field, migrate the data, then delete the old field.
    – leymannx
    Oct 21 '20 at 6:36
2

Unfortunately, as suggested, programmatically changing the config won't work, as all dates will show empty. Which explains why it's locked in the UI.

You'll need to browse your DB and find the node__{field_date} table and manually remove the time part for all values.

enter image description here

Then make a sql export of this table.

Repeat the above with node_revision__{field_date}.

In Drupal, manage fields, delete your field_date. Recreate field_date with Date only. Import your sql db table exports you had made.

Flush cache in Drupal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.