addhours using Calendar employee


I want to calculate the sum of “08/09/11 10:00:00” and the duration of 10 hours using calendar emplyees"8H".
Start Date: 09/08/11 10:00:00
Duration: 10 Hours
End Date: 08/10/11 12:00:00

Hello you can use the addHours method of the DateTimeUtil class to add hours to a field of type UTCDateTime:

DateTimeUtil::addHours Method

client server public static utcdatetime addHours(utcdatetime t, int value)

But i want to use calendar employee because with calendar employee (1 Day = 8 H) ???[:(]


You can make use of following arithmetic operators to perform calculations:


i = 100 div 21;

Returns the integer division of 100 by 21. i=4 (4*21 = 84, remainder 16).


i = 100 mod 21;

Returns the remainder of the integer division of 100 by 21. i=16. 86400

The smallest unit of time in utcdatetime is one second. Since you are using utcDateTime you’ll have to convert the hours to seconds i.e. the total number of hours to add (as in ex. you have given 10) and the number of hours that make a calendar day (as in ex. you have given 8).

You can use the approach as shown below:

int numberOfDays;

int64 secondsIntotalHours, secondsInCalendarDay, numberOfSeconds;

utcDateTime toDateTimeTotal, fromDateTimeTotal;

utcDateTime toDateTimeCalendar, fromDateTimeCalendar;

secondsIntotalHours = DateTimeUtil::getDifference(toDateTimeTotal, fromDateTimeTotal);

secondsInCalendarDay = DateTimeUtil::getDifference(toDateTimeCalendar, fromDateTimeCalendar);

numberOfDays = secondsIntotalHours div secondsInCalendarDay;

numberOfSeconds = secondsIntotalHours mod secondsInCalendarDay;

EndDate = DateTimeUtil::addDays(StartDate, numberOfDays);

EndDate = DateTimeUtil::addSeconds(EndDate, numberOfSeconds);

Ths it works properly.