Difference between two fields

Created on 18 May 2022, over 2 years ago
Updated 30 June 2022, over 2 years ago

I'm trying to figure out how to use this complex module.
I have two fields that I'd like to compute the difference, field_cp1_time_in and field_cp1_time_out, and have no idea where to start.

I tried making a Custom Text field and also tried applying a range difference, but this doesn't work.

Any help is appreciated. Thanks

πŸ’¬ Support request
Status

Closed: works as designed

Version

2.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States stinky

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tlwatson

    For anyone else trying to do this, yes it's possible with Custom Text. First make sure that the fields are currently outputting a Twig-readable date format (the HTML full date/time worked best for me). Then use the date filter to convert to UTF format, so Twig knows what it's doing "math" on. Like:

    {{ field_cp1_time_out|date('U') - field_cp1_time_in|date('U') }}
    

    What you'll get here is a UTF-dated value difference in seconds. You can then reformat it back to whatever you want with the date filter, such as minutes / seconds:

     {{ (field_cp1_time_out |date('U') - field_cp1_time_in|date('U'))|date('i:s') }}
    

    I tend to write this out in a longer form in the view to make it more legible, but there's the gist of it. You may have to specify timezone if it's not cooperating.

Production build 0.71.5 2024