Skip Navigation

[Resolved] date/time calculations in view

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 2 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2329009

Tell us what you are trying to do?

Present a view that shows the result of a calculation of multiple repeating group fields. these are date/time fields.

the calculation would take the 'in' and 'out' date/time for each of the records in the repeating group, and calculate the number of hours difference between the in and out. and finally, to sum all of those results for a grand total.

part 2: would it be possible to filter and/or sort based on that grand total?

I don't need detail - I just need to know if this is possible using toolset/toolset shortcode (and not straight up coding external to toolset) in order to accept or decline a job.

thank you!

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hasn't been developed yet.

#2329285

Hello,

There isn't such kind of built-in features within Toolset plugins, Toolset Blocks/Views plugin does not calculate the data, so you will need to create your own custom shortcodes to calculate the results.

#2329291

yes, I understand there are no built in functions, but can we say there is nothing blocking me from making this happen by using shortcode? are there limitations on the datetime field, for example - anything that just isn't possible when it comes to calculations for data presented in a view, or for being able to filter on those calculations? thank you!

#2329341

Toolset custom date field stores value in timestamp format:
hidden link
You can use date field values to calculate what you want.

Toolset repeatable field groups(RFG) are based on one-to-many relationship, each item of RFG is also a custom post(post type slug is your RFG slug), you can use relationship API function toolset_get_related_posts() to get items of repeatable field group, see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

#2329705

thank you Luo, and can you also confirm there's no reason why I wouldn't be able to use that calculated field result in a filter? ie, filter for everything where the fields total x amount. and also to be able to sort based on the calculated field result. thank you!

#2329835

Toolset Blocks/Views plugins are using WordPress built-in class WP_Query to query WordPress posts, there isn't such kind of feature to filter/order the results by calculated field result, see WP document:
https://developer.wordpress.org/reference/classes/wp_query/