Sprintf formatting form and list element

tmntmn

Member
Hi All

I've calc elemet that calculates the elapsed time from two other elements (starttime and endtime)

The result comes from this code:

Code:
 return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);

The format of the database field is time HH:MM:SS (hour:minutes:seconds) this works OK.

I would like to see only the HH:MM in form and list views, not the seconds.

I've tried to use sprintf on the Format String field in the calc element, but I can't make it work, what would be the correct sprintf format for this?

Best regards

Thomas
 
Gentle bump on this

I think I've tried all kinds of combinations including:
%H:%M
%02:%02
("%02d:%02d", $hours, $minutes)
and so on.

Best regards

Thomas
 
hi can you post the calculation you are using (screen shot of the calc settings would be best)?
How are $hours, $minutes etc set?
I'm not really sure you can do what you want here though, the calc element 'Format string' option is only going to be able to wrap text around the calculated value.
 
Hi Rob

Screendump of element settings:
calc-element.png

In the form view the calc gives HH:MM:SS, what I would like is only HH:MM to be shown as the seconds are never used and are confusing the users.
time.png
I've solved it in the list view, by copying the list and change the element to time, formatting the field to HH:MM and then made the edit link point back to the original form.

best regards

Thomas
 
I presume you need to store the h:m:s and not just h:m?

To get round that the only thing I can think of is to create a new calc element which is shown to the user with the same calc except for the last line which you can replace with

Code:
return sprintf("%02d:%02d", $hours, $minutes);

Then set the original element to be hidden. Thus you can store the h:m:s and hide that from the user, instead showing the calc element with the h:m formatting
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top