JavaScript - add 1 hour

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 877
Location: Switzerland

JavaScript - add 1 hour

Post by mpol_ch »

Hello
I am using the following code to have in field "Bis" the time value of field "Vom". This working perfectly.
What I need is to have in field "Bis" the time value of field "Vom" + 1h or 60 Minutes. I am using phpmaker 11.0.5 and the extension "Time Picker". DB field type is "time".

Where can I start?

$( "#x_Vom" ).change(function() {
var Vom = $("#x_Vom").val();
$("#x_Bis").val(Vom);
});

Thanks
mpol_ch


mobhar
User
Posts: 11736

Post by mobhar »

Simply replace your code with this:

function addMinutes(time, minsToAdd) {
function D(J){ return (J<10? '0':'') + J;};
var piece = time.split(':');
var mins = piece[0]60 + +piece[1] + +minsToAdd;
return D(mins%(24
60)/60 | 0) + ':' + D(mins%60) + ':' + '00';
}

$("#x_Vom" ).change(function() {
var Vom = $("#x_Vom").val();
var Bis = addMinutes(Vom, '60');
$("#x_Bis").val(Bis);
});

Credit: stackoverflow.com/questions/17446466/add-15-minutes-to-string-in-javascript


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

thanks. It works perfect.

mpol_ch


Post Reply