Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating # of Days in past 3 months

Status
Not open for further replies.

mward04

Technical User
Jun 13, 2002
25
US
I am trying to create a query that will allow me to enter a date range, say between 4/1/02 and 5/1/02 (This part I've got). However, I want to know how many calendar days there are in the previous 3 months to 5/1/02. Anyone know how I would go about doing this??? In other words, I want to know how many calendar days are between 2/1/02 and 5/1/02.

Thanks in advance!
Mike
 
What you need to do is store the 01/01/?? in a variable and compare that julian 100001 with the current variable you would like to know.
 
Assuming your "5/1/01" is available for use / reference (I'll refer to it as DtEnd):

DaysinLastThreeMo = DateDiff("d", DtEnd, DateAdd("m", 3, DtEnd))
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
This may sound really stupid, so I apologize in advance, but where do I input:

DaysinLastThreeMo = DateDiff("d", DtEnd, DateAdd("m", 3, DtEnd))

Thanks!
Mike
 
Well, this code is assuming that your form's item (whether it be a text box or what not) value is set to DateDiff("d", DtEnd, DateAdd("m", 3, DtEnd))
..
Create a text box called DaysinLastThreeMo (this is the name, not the control source)... the conrol source will probably be a field in a table.

I'd put it in the VBA code behind the Form's On_Current section.. it'd look somtehing like
Private Sub Form_Current()
Me.DaysinLastThreeMo = DateDiff("d", DtEnd, DateAdd("m", 3, DtEnd))
End Sub

I believe that dtEnd is a variable that needs to be defined as well. -JPeters
These things take time...
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
 
Thanke JPeters, Wasn't EXACTLY what I had in mind, but quite servicable. From my perspective, DtEnd was the control on the form or [with the addition of ye olde square brackets] it could as easily be a field in the recordset. I had in mind making "DaysinLastThreeMo" a locally defined variable, calculated on one of the form events or on the change event of the DtEnd control ...

But these are implementation details which I had also assumed the poster would be able to deal w/ - so you intervention is (hopefully) more useful than the trivial expression I supplied.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top