Normal Topic Count in Date Interval.. (Read 889 times)
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Count in Date Interval..
Feb 26th, 2007 at 4:16pm
Print Post Print Post  
Hi-

 I use  This Statment to count the Workday : "WDays = DATE1 - DATE2"  
This simply calculates a number of days but i want to  subtract the  free Days, saturdays and sundays between the 2 dates.
How can i realise that?

Thank you for any suggestions.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Count in Date Interval..
Reply #1 - Feb 26th, 2007 at 5:10pm
Print Post Print Post  
Hello Amor,
The code below should calculate the workdays for you.

Code
Select All
var vDays as Int
var vTemp as Date

vTemp = Date1
vDays = 0

While vTemp > Date2
{
	If @DOW(vTemp) <= 5 Then
	{
		vDays = vDays + 1
	}

	vTemp = vTemp - 1
}
WDays = vDays
 

  
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Count in Date Interval..
Reply #2 - Feb 26th, 2007 at 6:00pm
Print Post Print Post  
Hello Ben,

Thank you for the Quick Replay!

I want to substract  these Days olso:

New Years Day 01 January  
Martin Luther King Day traditional on 17  January      
Presidents Day traditional on 12 February
Memorial Day traditional on 30 May  
Independence Day 04 July  
Laboratory Day 1st Monday in September  
Columbus Day traditional on 12 October  
Veteran Day traditional on 11 November  
Thanksgiving 4. Thursday in November  
Christmas Day 25 December
...

Must i use a Array or Globavlaue  ?
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Count in Date Interval..
Reply #3 - Feb 26th, 2007 at 10:45pm
Print Post Print Post  
Hello Amor,

Ben is currently working on writing several functions that will subtract the correct days for those holidays from the amount of work days. It make take a day or two to write them all the functions and test them to be sure that they work, but as soon as they are finished he will post them up here for you.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Count in Date Interval..
Reply #4 - Mar 2nd, 2007 at 7:13pm
Print Post Print Post  
Quote:
Hello Ben,
I want to substract  these Days also...




Hello Amor,
Below is the programming that will remove the weekends and holidays that you asked about.

Copy this section into Global Code:
Code
Select All
//=============================================================
//FUNCTION FOR FINDING A DAY BASED ON WHERE IT FALLS IN A MONTH
//=============================================================


Function FindADay(vYear as Int, vMonth as Int, vDOW as Int, vInstance as int) as Date
var vRemoveDay as Date
var vTempDate as Date
var vDayLoop as Int

	vDayLoop = 0
	vTempDate = @D(vMonth + ", 1, " + vYear)

If ((vInstance <= 5) and (vInstance > 0)) then
{
	while vDayLoop < vInstance
	{
		If @Dow(vTempDate) = vDOW then
		{
			vDayLoop = vDayLoop + 1
			If vDayLoop = vInstance then
			{
				vRemoveDay = vTempDate
			}
		}
		vTempDate = vTempDate + 1
	}
}
Else If (vInstance = 0) then
{
	while vDayLoop < vInstance
	{
		If @Dow(vTempDate) = vDOW then
		{
			vDayLoop = vDayLoop + 1
			If vDayLoop = vInstance then
			{
				vRemoveDay = vTempDate
			}
		}
		vTempDate = vTempDate - 1
	}
}
	Return(vRemoveDay)
End Function


//==============================================================
//FUNCTION CHECK DATE
//==============================================================


Function CheckDate(vDate, vBottom, vTop) as Int
var vRet as Int
	vRet = 0
	If ((vDate >= vBottom) and (vDate <= vTop))
	{
		vRet = 1
	}
Return(vRet)
End Function


//==============================================================
//FUNCTION
//==============================================================


Function DayFinder(vTop as Date, vBottom as Date, vDays as int) as int
var vFind_Date as Date
var vBottomYear as Int
var vTopYear as Int
var vTemp as Int

	vBottomYear = @Year(vBottom)
	vTopYear = @Year(vTop)
	vTemp = vBottomYear

	While vTemp <= vTopYear
	{
// FindADay(YEAR, MONTH, DOW #, INSTANCE OF [Between 0 and 5, use 0 to indicate LAST])
// U.S. Holidays

		vDays = vDays - CheckDate(@Str(vTemp +"/01/01"), vBottom, vTop)	    // New Years Day	  (Always January First)

		vDays = vDays - CheckDate(FindADay(vTemp, 1, 1, 3), vBottom, vTop)	    // MLK Day		  (Third Monday in January)

		vDays = vDays - CheckDate(FindADay(vTemp, 2, 1, 3), vBottom, vTop)	    // President's Day	(Third Monday in February)

		vDays = vDays - CheckDate(FindADay(vTemp, 5, 1, 0), vBottom, vTop)	    // Memorial Day	   (Last Monday in May)

		vDays = vDays - CheckDate(@Str(vTemp +"/08/04"), vBottom, vTop)		 // Independance Day     (Always July Fourth)

		vDays = vDays - CheckDate(FindADay(vTemp, 9, 1, 1), vBottom, vTop)	    // Labor Day		(First Monday of September)

		vDays = vDays - CheckDate(FindADay(vTemp, 10, 1, 2), vBottom, vTop)	  // Columbus Day	   (Second Monday of October)

		vDays = vDays - CheckDate(@Str(vTemp +"/11/11"), vBottom, vTop)		     // Veteran's Day	  (Always November Eleventh)

		vDays = vDays - CheckDate(FindADay(vTemp, 11, 4, 4), vBottom, vTop)	 // Thanksgiving Day     (Fourth Thursday of November)

		vDays = vDays - CheckDate(@Str(vTemp +"/12/25"), vBottom, vTop)		    // Christmas Day	  (Always December Twenty-Fifth)

		vTemp = vTemp + 1

	}

	Return(vDays)

End Function
 




Copy this section into whatever element's event you want to use:

Code
Select All
var vDays as Int
var vTemp as Date

vTemp = Date1
vDays = 0

While vTemp > Date2
{
	If @DOW(vTemp) <= 5 Then
	{
		vDays = vDays + 1

	}

	vTemp = vTemp - 1
}
vDays = DayFinder(Date1, Date2, vDays)
Wdays = vDays
 




If you run into any problems with this programming, please let me know.

-Ben
« Last Edit: Mar 2nd, 2007 at 9:52pm by Ben »  
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Count in Date Interval..
Reply #5 - Mar 7th, 2007 at 9:34pm
Print Post Print Post  
Hello BEN !

With a bit Modification  it works fine !

Thank you for the Help.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged