How to derive an interval from two dates?

Created on 11 January 2024, 6 months ago

I'm developing a classified ads system which includes a custom entity type. It has an expiry date field and a 'time_remaining' interval field that is to be calculated and stored when users pause their ads.

How would I programmatically set the interval field value based on the time between now() and my date field?
And if I store the period in hours, is there a way of displaying the time remaining in days? Or should I be using the duration_field module instead? I'm trying to stick to dependencies of commerce and related modules where possible.

πŸ’¬ Support request
Status

Active

Version

1.12

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom griz

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

Comments & Activities

Production build 0.69.0 2024