Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 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 09:04 Go to next message
Julia Antoniuk is currently offline Julia Antoniuk
Messages: 5
Registered: 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...

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 18:02 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 1595
Registered: 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

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
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 Go to previous messageGo to next message
Julia Antoniuk is currently offline Julia Antoniuk
Messages: 5
Registered: 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
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 21:40 Go to previous message
Michael Williams is currently offline Michael Williams
Messages: 1595
Registered: July 2009
Senior Member

Great! Glad you got it working!

Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Previous Topic:Can we get row number in a computed column in dataset??
Next Topic:Websphere desn't like BIRT...
Goto Forum:
  


Current Time: Mon Sep 15 04:24:11 GMT 2014

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

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