|
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 |
|
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 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02931 seconds