1

How to get substring of a SearchKit result column? I want to truncate the event start time from 17:15:00 to just 17:15.

What I have:

  • My test setup is newest WP 6.3.2 and newest CiviCRM 5.66.0.
  • CiviEvent: several events, with a starting date and time, e.g. 17:15.
  • SearchKit: a search that gives me open events in the next 2 weeks.
    The result presents no actions, no sorting, just a static table listing.
  • Form Builder: a form to hold the results from the search.
  • WordPress: a page that contains the shortcode with my search.

What I want:

  • The final output contains a column with event start time including seconds. It is silly to show an event start time with seconds - and I understand that this comes from the timestamp format in the database.
  • I do not see any suitable field transformation that I could apply in the SearchKit.
  • In the reports output part of SearchKit, each column has the Rewrite Text function using "SMARTY conditions" but it is not clear to me how that works. My latest attempt is [{TIME_start_date|substr:0:5}] but that generates no output. Can you give an example?
  • I cannot think of another way to truncate the time value, or any way to do any kind of substring operation at all.

How can I get rid of the seconds in the time column?

event listing

field transformations

(ignore the missing localisation of the weekday and month words)

2
  • I think SearchKit is sorely missing a "Format Date" column setting. Do you think you could sponsor that feature?
    – Coleman
    Oct 22, 2023 at 11:15
  • Depends on what you mean by the word "sponsor", @Coleman? I sadly cannot provide funding, and my PHP skills are not up to snuff ... but I might be able to contribute in other ways. Oct 24, 2023 at 5:36

1 Answer 1

3

Agree with Coleman that it would be great to have Format Date in SearchDisplays.

If you want to do this in the Smarty rewrite, you can do something like {"[start_date]"|date_format:"%H:%M"}, without the field transformation.

1
  • I made a small adjustment to match the actual field name: {"[TIME_start_date]"|date_format:"%H:%M"} and that worked like a charm! <3 Thank you Lars! I can see this code is syntactically a little different from my previous, failed attempts. I was close though :-) Gotta learn more about how Smarty is written inside SearchKit now. Oct 24, 2023 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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