How to calculate the number of days betwen two dates? [message #974707] |
Wed, 07 November 2012 04:04  |
Eclipse User |
|
|
|
Hi,
how can I calculate the number of days betwen two dates excluding the weekend days?
For example, I want to know hom many working days are betwen 1. Oct 2012 and today?
The
BirtDateTime.diffDay(BirtDateTime.today(), "2012-10-01 10:01:04.531+0200")
is unfortunately not an option as it returns the number of ALL days between...
Thank you in advance.
|
|
|
|
Re: How to calculate the number of days betwen two dates? [message #976463 is a reply to message #975224] |
Thu, 08 November 2012 10:50   |
Eclipse User |
|
|
|
Hi Michael,
thank you so much! It works!
The script got a little bit more complicated, but works perfectly!
I made a first version which calculates the number of working days in current month.
It looks like this:
var WDays, WDays_until_First_Sun_of_Month, WDays_afrter_Last_Sun_of_Month
WDays = 5*(BirtDateTime.diffWeek ( BirtDateTime.addDay(BirtDateTime.firstDayOfMonth(BirtDateTime.today()), (7-BirtDateTime.weekDay(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),2))), //first Sunday of Month
BirtDateTime.addDay(BirtDateTime.addMonth(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),1), ( - BirtDateTime.weekDay(BirtDateTime.addMonth(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),1),2) ) //last Sunday of Month
)) // full Weeks in the Month
) // W_Days between the first Sunday of Month and last Sunday of Month
switch(7- BirtDateTime.weekDay(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),2)-1)
{
case -1:
WDays_until_First_Sun_of_Month = 0
break;
case 0:
WDays_until_First_Sun_of_Month = 0
break;
default:
WDays_until_First_Sun_of_Month=(7- BirtDateTime.weekDay(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),2)-1)
}
switch(1 - BirtDateTime.weekDay(BirtDateTime.addMonth(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),1),2))
{
case 0:
WDays_afrter_Last_Sun_of_Month = -5
break;
case -6:
WDays_afrter_Last_Sun_of_Month = -5
break;
default:
WDays_afrter_Last_Sun_of_Month=1 - BirtDateTime.weekDay(BirtDateTime.addMonth(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),1),2)
}
WDays= WDays+WDays_until_First_Sun_of_Month-WDays_afrter_Last_Sun_of_Month
// LEGEND:
//7- BirtDateTime.weekDay(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),2) // days between the firts day of month and first Sunday of Month
//1 - BirtDateTime.weekDay(BirtDateTime.addMonth(BirtDateTime.firstDayOfMonth(BirtDateTime.today()),1),2) // days between the last Sunday of Month and last day of Month
|
|
|
|
Powered by
FUDForum. Page generated in 0.03193 seconds