Currently this calculation creates some very odd time values even though i am formatting the field hh:mm. i assume i have to force a format somewhere in the calculation but i am unsure which function to use
i’m playing around with the get/set fx now. wondering would it be easier, since i already have the multiplied value as a decimal to convert this to a time?
eg 15.75 becomes 15:45 (HH:mm)
Is this an easier conversion and how do i convert it?
Here is my current method, not sure if i am on the right track
// extract left 2 numbers and right 2 numbers (not sure if this is the best way to do it?)
var dec_upper = utils.stringLeft(inventory_to_build_labour_lines.time_total_dec_build, 2);
var dec_lower = utils.stringRight(inventory_to_build_labour_lines.time_total_dec_build, 2);
// convert dec to minutes
var time_lower = dec_lower * .6;
// create the full converted time
var time_build = dec_upper + “:” + time_lower;
// insert into datetime field (its here i believe the error exists)
time_total_build = time_build;
I would prefer not to do this by method but as a calculation if possible.
Multiplying a datetime field by a number field = calculated datetime
Converting a number field (this has already been multiplied and formatted 00.00) into a datetime field
Whichever way is the easiest! This is the first thing to determine
The previous post referred to the 2. above and therefore doesn’t involve datetimes until the end.
if i try by 1. above i can use the following in a method:
// extract hours and minutes to create separate variables
var hours = time_total.getHours();
var minutes = time_total.getMinutes();
// multiply the variables by the number field
var time_build_hours = hours * kit_multiplier;
var time_build_minutes = minutes * kit_multiplier;
fine, all works well what i don’t know is how to insert these values back into a datetime field using the setHours/setMinutes fx? i keep getting errors and there is no example code to follow in developer.
Also if the variable “time_build_minutes” is greater than 60 will this cause issues inserting back into minutes field?
How do i use the setHours/Minutes function to insert these variables into the datetime field?
appreciate your patience! this seems a trivial thing to do and takes me about 30 secs. in FMP. Have you tried this yourself?
fine, all works well what i don’t know is how to insert these values back into a datetime field using the setHours/setMinutes fx? i keep getting errors and there is no example code to follow in developer.
Can you give me what you are doing here? Should not give any errors.
Also if the variable “time_build_minutes” is greater than 60 will this cause issues inserting back into minutes field?
It will be no issue at all, 70 minutes will add 1 hr and 10 minutes.
How do i use the setHours/Minutes function to insert these variables into the datetime field?
date.setHours(xx) and date.setMinutes(xx) or date.setHours(date.getHours + xx) etc. But again, can you show that part of your method?
// extract hours and minutes to seperate variables
var hours = time.getHours();
var minutes = time.getMinutes();
// multiply the variables by the number field
var build_hours = hours * build_multiplier;
var build_minutes = minutes * build_multiplier;
// insert into total time field
total_build_time = total_build_time.setHours(build_hours);
total_build_time = total_build_time.setMinutes(build_minutes);
The trick was how you assign in the values at the end which i didn’t have right. I’ll play around changing this so its a calculated field not a method.