Duration days in the month for weighted distribution.

As in this excel,

I want calculate dates in each month. To get this data, I can calculate with my brain but not KNIME…
I need help here.
Then because I have units in each month

and I know the full dates of the month

I can get

FinalValues will be Dates divide FullDates x Units.
datecal.pptx (34.1 KB)

DateCal_2.xlsx (78.7 KB) DateCal_20200420.xlsx (38.8 KB)

The date does not contradict (in/exclusive) because I want to have the duration.
so the start should come from end of month minus the start date and end should come from the beginning of the month minus the end date and add minus again.
Is there any simple way to solve this?

in VBA it should be
dateW = DateSerial(lngTounen, lngMcnt, 1)

                    If Year(dateW) = Year(dateS) And month(dateW) = month(dateS) And _
                       Year(dateW) = Year(dateE) And month(dateW) = month(dateE) Then
                        dateMS = dateS
                        dateME = dateE
                        flgMatch = True
                    ElseIf Year(dateW) = Year(dateS) And month(dateW) = month(dateS) Then
                        
                        dateMS = dateS
                        dateME = DateSerial(Year(dateS), month(dateS), Day(DateSerial(Year(dateS), month(dateS) + 1, 0)))
                        flgMatch = True
                    ElseIf Year(dateW) = Year(dateE) And month(dateW) = month(dateE) Then
                        
                        dateMS = DateSerial(Year(dateE), month(dateE), 1)
                        dateME = dateE
                        flgMatch = True
                    Else
                        Dim dateSfirst As Date
                        Dim dateElast As Date
                        dateSfirst = DateSerial(Year(dateS), month(dateS), 1)
                        dateElast = DateSerial(Year(dateE), month(dateE), Day(DateSerial(Year(dateE), month(dateE) + 1, 0)))
                       
                        If dateSfirst < dateW And dateW < dateElast Then
                            dateMS = DateSerial(Year(dateW), month(dateW), 1)
                            dateME = DateSerial(Year(dateW), month(dateW), Day(DateSerial(Year(dateW), month(dateW) + 1, 0)))
                            flgMatch = True
                        End If

                    End If

Try this:
KNIME_forum23048_pigreco.knwf (43.6 KB)

Thank you very much. This can solve the problem.

2 things I added modifications:

  1. Add column append to add No 1,2,3… information

  2. For some data needs to add 1 more day.

out_days=0;

if (c_diff_from>=0 && c_diff_from1<0)
{
if (c_diff_to1>=0 && c_diff_to>0)
{
out_days=c_diff_from.intValue();
}
else if (c_diff_to1>=0 && c_diff_to<0)
{
out_days =(int)(c_diff_to1.intValue()+c_diff_to.intValue()+c_diff_from.intValue()+c_diff_from1.intValue())/2 + 1;
}
}
else
if (c_diff_from>=0 && c_diff_from1>=0)
{
if (c_diff_to1>=0 && c_diff_to>=0)
{
out_days=c_monthlength.intValue();
}
else if (c_diff_to1>=0 && c_diff_to<0)
{
out_days=c_diff_to1.intValue() + 1;
}

}

If you want include last day, yes, increment is right! :slight_smile:

Yep. Absolutely right. Thank you very much.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.