Eclipse Community Forums Forum Search:

Home » Eclipse Projects » BIRT » How to calculate the number of days betwen two dates?
How to calculate the number of days betwen two dates? Wed, 07 November 2012 09:04
 Julia AntoniukMessages: 5Registered: November 2012 Junior Member
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...

Re: How to calculate the number of days betwen two dates? [message #975224 is a reply to message #974707] Wed, 07 November 2012 18:02
 Michael WilliamsMessages: 1925Registered: July 2009 Senior Member
You'll probably have to write a little more script on your own. One way to do it would be to figure out what day of week the first and last days are on, then trim down the first or last date to be a group of perfect weeks and start your count of days with the non weekend days you nipped off the range. To do the rest of the total, you'd just take your even weeks range you created and find the number of days, then subtract 2 days for every 7. Hope this makes sense. Let me know.

Michael

Developer Evangelist, Silanis
Re: How to calculate the number of days betwen two dates? [message #976463 is a reply to message #975224] Thu, 08 November 2012 15:50
 Julia AntoniukMessages: 5Registered: November 2012 Junior Member
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
)) // 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)
}

{
case 0:
WDays_afrter_Last_Sun_of_Month = -5
break;
case -6:
WDays_afrter_Last_Sun_of_Month = -5
break;

default:
}

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
Re: How to calculate the number of days betwen two dates? [message #976806 is a reply to message #976463] Thu, 08 November 2012 21:40
 Michael WilliamsMessages: 1925Registered: July 2009 Senior Member
Great! Glad you got it working!

Michael

Developer Evangelist, Silanis
 Previous Topic: Can we get row number in a computed column in dataset?? Next Topic: Websphere desn't like BIRT...
Goto Forum:

Current Time: Tue Jun 19 09:06:47 GMT 2018