Calculate no of days in a month within a specified date range
Author Message
Calculate no of days in a month within a specified date range

I need a function to check the number of days within a
specified month.
For example :

Specified Period range (10 Jan 2003 and 28 Nov 2003),
check no of days in between a month.

1.      Input is 200301, the result is 10
2.      Input is 200311, the result is 28
3.      Input is 200303, the result is 31
4.      Input is 200304, the result is 30
5.      Input is 200212, the result is 0/Null
6.      Input is 200312, the result is 0/Null

Thanks

Sat, 26 Nov 2005 21:27:16 GMT
Calculate no of days in a month within a specified date range

Quote:
> I need a function to check the number of days within a
> specified month.
> For example :

> Specified Period range (10 Jan 2003 and 28 Nov 2003),
> check no of days in between a month.

> 1.     Input is 200301, the result is 10
> 2.     Input is 200311, the result is 28
> 3.     Input is 200303, the result is 31
> 4.     Input is 200304, the result is 30
> 5.     Input is 200212, the result is 0/Null
> 6.     Input is 200312, the result is 0/Null

' Adjust start of month
dtStartOfMonth = DateSerial(SomeYear, SomeMonth, 1)
If dtStartOfMonth < dtMinimumDate then
dtStartOfMonth = dtMinimumDate

End If

' Adjust end of month
dtEndOfMonth = DateSerial(SomeYear, SomeMonth + 1, 0)
If dtMaximumDate < dtEndOfMonth Then
dtEndOfMonth = dtMaximumDate

End If

' Compare values: make sure they're not overlapping
If dtStartOfMonth < dtEndOfMonth Then
varDaysWithin = DateDiff("d", dtStartOfMonth, dtEndOfMonth)

Else
' Error value
varDaysWithin = Null

End If

Bear in mind that this is not tested!

Hope that helps

Tim F

Sun, 27 Nov 2005 02:43:34 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages