Skip to main content



      Home
Home » Archived » BIRT » How to calculate the number of days betwen two dates?
How to calculate the number of days betwen two dates? [message #974707] Wed, 07 November 2012 04:04 Go to next message
Eclipse UserFriend
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 #975224 is a reply to message #974707] Wed, 07 November 2012 13:02 Go to previous messageGo to next message
Eclipse UserFriend
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.
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: How to calculate the number of days betwen two dates? [message #976806 is a reply to message #976463] Thu, 08 November 2012 16:40 Go to previous message
Eclipse UserFriend
Great! Glad you got it working!
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 Mar 25 17:59:22 EDT 2025

Powered by FUDForum. Page generated in 0.03193 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top