PC Review


Reply
Thread Tools Rate Thread

Custom Date Partition Function

 
 
Lunch
Guest
Posts: n/a
 
      13th Apr 2010
I need to create a custom date partition function so I can run counts between
the dates the user sets and the number of segments someone sets. Think of it
as a the partition function except with dates. Below is a break down of
things conceptually and then a rough outline on some VBA that tries to do
this stuff………..any help on getting the function to work would be greatly
appreciated.

*************************************************************
Manual Example
*************************************************************

****************
Start Date: 1/1/2009
End Date: 2/1/2009
Segments: 4
****************

****************
Calculate Segment Length and Segments
****************
(EndDate)-(StartDate) = Length of Segment in days
Example: (2/1/2009)-(1/1/2009)=31

Round((Length of Segment in Days) / (Segments)) = Days to add
Example: Round(31/ 4) = 8

Break dates into segments:
Segment1 which is 1/1/2009 = (StartDate)
Segment2 which is 1/9/2009 = (1/1/2009+8)
Segment3 which is 1/17/2009 = (1/9/2009+8)
Segment4 which is 1/25/2009 = (1/17/2009+8)

****************
Example Start Data
****************
ID Date
1 1/1/2009
2 1/8/2009
3 1/16/2009
4 1/24/2009
5 1/25/2009
6 2/1/2009





****************
Intended End Product so I can run counts on Id’s between dates
****************
ID Date DatePartition
1 1/1/2009 1/1/2009
2 1/8/2009 1/1/2009
3 1/16/2009 1/17/2009
4 1/24/2009 1/17/2009
5 1/25/2009 1/25/2009
6 2/1/2009 1/25/2009


****************
Rough Outline Of VBA Code…..doesn’t work but it’s conceptually what I’m
trying to do……
****************

Function DatePartition(StartDate As Date, EndDate As Date, DateVar As Date,
Segments As Integer)
'Calculate the difference in start date and end date in days then divide by
the number of segments
SegmentLength = Round((datediff("d", StartDate, EndDate) / Segments))

'Create temporary segments using the text date seg and the counter i so
dateseg1-datesegn
i = 1
Do Until i = Segments + 1
myvarname = "dateseg" & i 'increment the variable names by i
myvarname = DateAdd("d", SegmentLength * i, StartDate) 'increment the
segment length by i
i = i + 1
Loop

'Loop through temporary segments and place queried dates into segments
x = Segments
Do Until x = 0
If DateVar < "dateseg" & 8 Then 'if the queried date is less than the
datesegment it's in that segment
DatePartition = "dateseg" & x
x = x - 1
Loop
End Function

Any takers on helping me figure this out?

 
Reply With Quote
 
 
 
 
Daniel Pineault
Guest
Posts: n/a
 
      14th Apr 2010
To calculate your 'Length of Segment in days' simply use the DateDIff().

What is your 'Segments'? I am confused by it, what does it represent?
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Lunch" wrote:

> I need to create a custom date partition function so I can run counts between
> the dates the user sets and the number of segments someone sets. Think of it
> as a the partition function except with dates. Below is a break down of
> things conceptually and then a rough outline on some VBA that tries to do
> this stuff………..any help on getting the function to work would be greatly
> appreciated.
>
> *************************************************************
> Manual Example
> *************************************************************
>
> ****************
> Start Date: 1/1/2009
> End Date: 2/1/2009
> Segments: 4
> ****************
>
> ****************
> Calculate Segment Length and Segments
> ****************
> (EndDate)-(StartDate) = Length of Segment in days
> Example: (2/1/2009)-(1/1/2009)=31
>
> Round((Length of Segment in Days) / (Segments)) = Days to add
> Example: Round(31/ 4) = 8
>
> Break dates into segments:
> Segment1 which is 1/1/2009 = (StartDate)
> Segment2 which is 1/9/2009 = (1/1/2009+8)
> Segment3 which is 1/17/2009 = (1/9/2009+8)
> Segment4 which is 1/25/2009 = (1/17/2009+8)
>
> ****************
> Example Start Data
> ****************
> ID Date
> 1 1/1/2009
> 2 1/8/2009
> 3 1/16/2009
> 4 1/24/2009
> 5 1/25/2009
> 6 2/1/2009
>
>
>
>
>
> ****************
> Intended End Product so I can run counts on Id’s between dates
> ****************
> ID Date DatePartition
> 1 1/1/2009 1/1/2009
> 2 1/8/2009 1/1/2009
> 3 1/16/2009 1/17/2009
> 4 1/24/2009 1/17/2009
> 5 1/25/2009 1/25/2009
> 6 2/1/2009 1/25/2009
>
>
> ****************
> Rough Outline Of VBA Code…..doesn’t work but it’s conceptually what I’m
> trying to do……
> ****************
>
> Function DatePartition(StartDate As Date, EndDate As Date, DateVar As Date,
> Segments As Integer)
> 'Calculate the difference in start date and end date in days then divide by
> the number of segments
> SegmentLength = Round((datediff("d", StartDate, EndDate) / Segments))
>
> 'Create temporary segments using the text date seg and the counter i so
> dateseg1-datesegn
> i = 1
> Do Until i = Segments + 1
> myvarname = "dateseg" & i 'increment the variable names by i
> myvarname = DateAdd("d", SegmentLength * i, StartDate) 'increment the
> segment length by i
> i = i + 1
> Loop
>
> 'Loop through temporary segments and place queried dates into segments
> x = Segments
> Do Until x = 0
> If DateVar < "dateseg" & 8 Then 'if the queried date is less than the
> datesegment it's in that segment
> DatePartition = "dateseg" & x
> x = x - 1
> Loop
> End Function
>
> Any takers on helping me figure this out?
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Custom Date Partition Function KARL DEWEY Microsoft Access Forms 1 14th Apr 2010 04:38 PM
Creating a custom function to interpret another custom engine func Ryan Microsoft Excel Programming 0 3rd Mar 2008 07:18 PM
Custom Date Validation Check Function John Smith Microsoft VB .NET 2 30th Mar 2007 07:04 PM
using autofilter custom function....filter of cells containing date... jerry1480 Microsoft Excel Worksheet Functions 2 4th Nov 2003 03:54 PM
Custom Date Function MM/YYYY nickelpar Microsoft Access VBA Modules 2 16th Oct 2003 06:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 AM.