Date/Time calculation

Hi,

I need to calcuate the date based upon the certain criteria which is as follow.

a) If the document is created between Firday 9:01AM - Tuesday 9:00AM, then the date would be next Friday.

b) If the document is craeted between Tuesday 9:01 AM - Firday 9:00AM then the date should be next Wedneday.

Any response would be appreciated?

Eddie

Subject: Date/Time calculation

Something like this maybe?

’ – CODE START –

Dim sess As New NotesSession

Dim dtNow As NotesDateTime

Dim iMoveDays As Integer



' Condition A) = Friday 9.01 AM -- Tuesday 9.00 AM

' Condition B) = Tuesday 9.01 AM -- Friday 9.00 AM



Set dtNow = New NotesDateTime(Cstr(Now))

Msgbox Weekday(dtNow.DateOnly),,dtNow.TimeOnly



Select Case Weekday(dtNow.DateOnly)

Case 1, 2, 7 ' Sunday, Monday and Saturday is ALWAYS condition A)

	iMoveDays = 6 - Weekday(dtNow.DateOnly)

	If iMoveDays < 1 Then

		iMoveDays = 6

	End If

Case 4, 5 ' Wen&Thur is ALWAYS condition B)

	iMoveDays = 8+3 - Weekday(dtNow.DateOnly)

Case 3, 6 ' Tue&Fri has to be examined by TIME-stamp

	If Weekday(dtNow.DateOnly) = 3 & Format$(dtNow.TimeOnly,"hh:mm") < "09.01" Then

		' This is condition A)

		iMoveDays = 3

	Elseif Weekday(dtNow.DateOnly) = 6 & Format$(dtNow.TimeOnly,"hh:mm") < "09.01" Then

		' This is condition B)

		iMoveDays = 5

	Elseif Weekday(dtNow.DateOnly) = 3 Then

		' This is condition B)

		iMoveDays = 5

	Elseif Weekday(dtNow.DateOnly) = 6 Then

		' This is condition A)

		iMoveDays = 3

	End If

End Select

Call dtNow.AdjustDay(iMoveDays)

Msgbox dtNow.DateOnly & " Weekday: " & Weekday(dtNow.DateOnly),64,"Information"

’ – CODE END –

All You have to do is supply with the document date in the Set dtNow = New NotesDateTime().

hth

Subject: Date/Time calculation

Hey Eddie, try this out:

Create a Computed Text Field with the formula:

=======================================

var := @Weekday(@Created);

time := @Time(@Created);

time1 := @Time(09;00;00);

time2 := @Time(09;01;00);

DayValue := @If( (var = 3 & time < time1) | var = 2 | var = 1 | var = 7 | (var = 6 & time > time2) ; “Friday” ; (var = 6 & time < time2) | var = 5 | var = 4 | (var = 3 & time > time1) ; “Wednesday”;“”);

DayValue

=======================================

This will set the field value as per the criteria given, and then you can use this field value to set the another date.

Subject: RE: Date/Time calculation

Hi Guys,

Thanks for the responses. I got some more information from client and the requirements has been changed now.

I want to make it generic so that i can be used for any combination. let me explain the process.

The Job is being created and it have 48 hrs ( 2 working days) lead time to be completed. The cut off time is 09:00. There are two days a week for Pick up ( Tuesday, Thursday : 09:00) and the item will be delivered next day (24 hrs).

All the Paramenter should be configurable. e.g leadTime, cut-off time, Pick-up days, Delivery Time.

For Example, Job created on Monday 10:00AM. It should be completed within 48 hrs ( leadtime) which means it should be ready by Wed 10:00AM. The next Pick-up day is Thursday 09:00PM and therefore it should be delivered on Friday.

Weekends should be excluded from the working days.

e.g Job created on Friday 10:00AM should be ready by Tuesday 10:00. Because the Pick-up on Tuesday is 09:00 so it will be missed and it will also be delivered next friday.

I’m trying with the following logic which is working fine for all days except Friday. The time part is being ignored at the moment to work out the basic logic but need to be included later.

Please comment on to this code and any response would be appreciated.

weekday := @Weekday(OrderDate);

leadTime := 2;

Collday1 := 3;

Collday2 := 5;

CollDate1 := @Adjust(OrderDate;0;0; Collday1 - weekday ;0;0;0);

CollDate2 := @Adjust(OrderDate;0;0; Collday2 - weekday ;0;0;0);

n := 1;

PDate := @Adjust(OrderDate;0;0; leadTime;0;0;0);

x := @BusinessDays(OrderDate; PDate;1:7) - 1;

@While(x <= leadTime;

PDate := @Adjust(OrderDate;0;0; n + leadTime;0;0;0);

x := @BusinessDays(OrderDate;PDate;1:7) - 1;

n := n + 1);

Pickeddate1 := @Adjust(PDate;0;0; -1;0;0;0);

Pday := @Weekday(Pickeddate1);

Pickeddate := @If(Pday = 1; @Adjust(Pickeddate1;0;0; - 2;0;0;0);

Pday = 7; @Adjust(Pickeddate1;0;0; - 1;0;0;0);

Pickeddate1);

DistDate := @If(( Pickeddate < CollDate1);CollDate1 ;

(Pickeddate >= CollDate1) & (Pickeddate < CollDate2) ; CollDate2 ;

(Pickeddate >= CollDate2); @Adjust(CollDate1;0;0; 7 ;0;0;0);

@Adjust(CollDate2;0;0; 7 ;0;0;0));

delDate := @Text(@Date(@Adjust(DistDate;0;0; 1 ;0;0;0)));

delDate

Subject: RE: Date/Time calculation

Hi Eddie

Try this out, now I am considering every Job as a Document. So put a Computed Date/Time field in the Form (which is the form of the document) and set the properties such that it shows time (hours, minutes and seconds). Insert this formula in the field value, this will directly give the Delivary Time after caluculating the Pick Up time as per your criteria.

=======================================

Time := @Time(09;00;00);

CreatedDay := @Weekday(@Created);

LeadTime := @If (CreatedDay = 5 | CreatedDay = 6 ; @Adjust(@Created;0;0;4;0;0;0) ; @Adjust(@Created;0;0;2;0;0;0));

LeadTimeDay := @Weekday(LeadTime);

LeadTimeTime := @Time(LeadTime);

AdjustTime1 := @Adjust(LeadTime ; 0;0;0;@Modulo((Time - LeadTimeTime)/3600;24);@Modulo((Time - LeadTimeTime)/60;60);@Modulo((Time - LeadTimeTime);60));

AdjustTime2 := @Adjust(LeadTime ; 0;0;1;@Modulo((Time - LeadTimeTime)/3600;24);@Modulo((Time - LeadTimeTime)/60;60);@Modulo((Time - LeadTimeTime);60));

AdjustTime3 := @Adjust(LeadTime ; 0;0;4;@Modulo((Time - LeadTimeTime)/3600;24);@Modulo((Time - LeadTimeTime)/60;60);@Modulo((Time - LeadTimeTime);60));

AdjustTime4 := @Adjust(LeadTime ; 0;0;5;@Modulo((Time - LeadTimeTime)/3600;24);@Modulo((Time - LeadTimeTime)/60;60);@Modulo((Time - LeadTimeTime);60));

AdjustTime5 := @Adjust(LeadTime ; 0;0;2;@Modulo((Time - LeadTimeTime)/3600;24);@Modulo((Time - LeadTimeTime)/60;60);@Modulo((Time - LeadTimeTime);60));

PickUpDate := @If( (LeadTimeDay = 3 & LeadTimeTime < Time) ; AdjustTime1 ; (LeadTimeDay = 2 & LeadTimeTime < Time) ; AdjustTime2 ; (LeadTimeDay = 2 & LeadTimeTime > Time) ; AdjustTime2 ;(LeadTimeDay = 6 & LeadTimeTime < Time) ; AdjustTime3 ; (LeadTimeDay = 6 & LeadTimeTime > Time) ; AdjustTime3 ; (LeadTimeDay = 5 & LeadTimeTime > Time); AdjustTime4 ; (LeadTimeDay = 3 & LeadTimeTime > Time) ; AdjustTime5 ; (LeadTimeDay = 4 & LeadTimeTime > Time) ; AdjustTime2 ; (LeadTimeDay = 4 & LeadTimeTime < Time) ; AdjustTime2 ; (LeadTimeDay = 5 & LeadTimeTime < Time); AdjustTime1 ; “”);

DelivaryDate := @Adjust(PickUpDate;0;0;1;0;0;0);

DelivaryDate

=======================================

You can get the Pick Up Date in the value “PickUpDate”.

Subject: RE: Date/Time calculation

That’s superb!!. Karthik U r star. Thanx alot.

Eddie