calculation with datetime

this is the code i use for a calcultion to show how much overtime a person has done.

var begin = new Date(abegin.getYear(),abegin.getMonth(),abegin.getDay(),abegin.getHours(),abegin.getMinutes(),abegin.getSeconds());
var eind = new Date(aeind.getYear(),aeind.getMonth(),aeind.getDay(),aeind.getHours(),aeind.getMinutes(),aeind.getSeconds());
var tijdtussen = new Date();
tijdtussen = eind - begin;
if ( tijdtussen.getMinutes() > 15 && tijdtussen.getMinutes() < 45)
{
tijdtussen.setMinutes(30);
}
else if ( tijdtussen.getMinutes() <= 15 )
{
tijdtussen.setMinutes(0);
}
else if ( tijdtussen.getMinutes() >= 45 )
{
tijdtussen.setMinutes(0);
tijdtussen.setHours(tijdtussen.getHours() + 1)
}
return tijdtussen;

but it shows nothing in the text field.

could you tell me whats wrong in my code ?

thx

You first declare a dateobject “tijdtussen”.
In the next line however, this date object changes into nr of milliseconds (the result of your substraction is not a date object anymore, so you can’t use the .getHours methods etc..anymore)
Try and run this piece of code in a global testscript and use the debugger to step through. Notice the change of the “tijdtussen” object.
(I’ve altered the code to handle your “tijdtussen” as a number.)

Hope this helps you out.

var abegin = new Date(2004, 3, 15, 15, 00, 00)
var aeind = new Date(2004, 3, 15, 16, 00, 00)

var begin = new Date(abegin.getYear(),abegin.getMonth(),abegin.getDay(),abegin.getHours(),abegin.getMinutes(),abegin.getSeconds()); 
var eind = new Date(aeind.getYear(),aeind.getMonth(),aeind.getDay(),aeind.getHours(),aeind.getMinutes(),aeind.getSeconds()); 
var tijdtussen = new Date();//this line can be deleted
tijdtussen = eind - begin; 
tijdtussen = tijdtussen/(1000*60)//convert milliseconds to minutes
if( tijdtussen> 15 && tijdtussen < 45) 
{ 
	tijdtussen = 30; 
} 
else if ( tijdtussen <= 15 ) 
{ 
	tijdtussen = 0
} 
else if ( tijdtussen >= 45 ) 
{ 
	tijdtussen = 60
} 
application.output(tijdtussen);