Converting Date & Time

Hi:

I’m struggling to count date & time in Notes. I can count days, times and exclude the business days. but when everything comes together, it can’t work. On top of that, the counting should be based on 8-hour per day.

Exp: hours = endDate - startDate

If 1:

startDate = 23rd Nov 1500 and

endDate = 24th Nov 1000

it should return 3 hours (2 working hours on 23rd and 1 working hour on 24th)

If 2:

startDate = 23rd Nov 1000 and

endDate = 27th Nov 1500

I can get 3 days which is correct but what I want the result is 21 hours

I store the date & time together in endDate and startDate. Shall I split it? I treid but still it doesn’t work. I include @businessDay in my formula coz I want to exclude sat & sun.

I hope someone may give me a COMPLETE CODE. if I used a step-by-step logic, of course it works.

Pls help.

Many thanks.

Subject: Converting Date & Time

I found this in my jar of snippets…hopefully somethign useful in here

Calc #business days between 2 dates

Code: Button:

Check := @If(Startdate = “”; 1; EndDate = “”; 1; 0);

@If(Check; @Do(@Prompt([OK]; “No Values”; “You must enter starting and ending dates.”); @Return(“”)); “”);

HolidayList := @DbColumn(“”; “”; “($Holidays)”; 2);

@SetField(“Holidays”; HolidayList);

@Environment(“HolidayList”; @Implode(HolidayList; “;”));

@Environment(“Iterations”; @Text(((EndDate - StartDate) / (24 * 60 * 60)) + 1));

@Environment(“StartDate”; @Text(StartDate));

@Environment(“SlidingDate”; @Text(StartDate));

@Environment(“EndDate”; @Text(EndDate));

@Environment(“WorkDays”; “0”);

@Command([FileSave]);

@Command([FileCloseWindow]);

@Command([ToolsRunMacro]; “($Add-A-Day)”)

Execute-Once Macro “($Add-A-Day)”:

REM “ADD-A-DAY Macro”;

REM "Recursive macro to check if dates fall on weekends ";

REM “and holidays and increment a working day count.”;

REM “Retrieve all the environment variable”;

Iterations := @TextToNumber(@Environment(“Iterations”));

Sdate := @TextToTime(@Environment(“SlidingDate”));

EndDate := @TextToTime(@Environment(“EndDate”));

WorkDays := @TextToNumber(@Environment(“WorkDays”));

Holidays := @Explode(@Environment(“HolidayList”); “;”);

REM “Calculate Add a Day - will be zero or one”;

AddDay := @If(@Weekday(Sdate) = 1; 0; @Weekday(Sdate) = 7; 0; Sdate > EndDate; 0; @Text(Sdate) = Holidays; 0; 1);

REM “Check if there are any more iterations to do”;

REM “If not, call a macro to update the fields”;

REM “If yes, then save the new values and call the recursion routine”;

@If(Iterations = 0; @Do(@Command([ToolsRunMacro]; “($SetNumDaysField)”); @Command([EditDocument]; “1”)); @Do(@Environment(“Iterations”; @Text(Iterations - 1)); @Environment(“SlidingDate”; @Text(@Adjust(Sdate; 0; 0; 1; 0; 0; 0))); @Environment(“WorkDays”; @Text(WorkDays + AddDay)); @Command([ToolsRunMacro]; “($Recurs-Add)”)));

SELECT @All

Execute-Once Macro “($Recurs-Add)”:

@Command([ToolsRunMacro]; “($Add-A-Day)”);

SELECT @All

Filter Macro “($Recurs-Add)”:

FIELD NumDays := @Environment(“WorkDays”);

SELECT @All

Subject: Converting Date & Time

Heres a snippet - script

Calculate Date difference

Dim today_1 As NotesDateTime

Dim created As notesdatetime

For i = 1 To 1000

chris1 = doc.getitemvalue(“installer”)

If chris1(0)= chris(0) Then

Set doc = view.getnextdocument(doc)

Else

simone = today_1.timedifference(created) This is the actuall calculation that script does

DaysBetween = simone \ 86400 ’ 24 * 60 * 60 *** this returns a number or daysbetween document created and todaysdate***

If DaysBetween > 30 Then

If chris(0) = “” Then

Set doc = view.getnextdocument(doc)

Else

jason = doc.getitemvalue(“date_com”)

chris=doc.getitemvalue(“Installer”)

If Not jason(0) = “” Then

Set doc = view.getnextdocument(doc)

Else

End If

End If

End If

End If

Set doc = view.getnextdocument(doc)

jasonjason = doc.getitemvalue(“date”)

Set created = New notesdatetime(jasonjason(0))

Next

End Sub

Subject: RE: Converting Date & Time

Tx April. appreciate your help. it brings me some sense.

cheers!