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!

Pulling the number of days in a given month from a date range 1

Status
Not open for further replies.

beverlee

Instructor
Oct 8, 2002
61
US
Seasons Greetings All!-

I need to pull the number of days in any given month from a date range. The start of the date range is a field called [hookupdate] and the end of the date range is a field called [enddate]. I need to be able to tell how many days in that range fall within any given month, but don't want to base it on the current date. The users may need to go back and pull historical data for reports and so I want them to be able to enter the [Begin Date] and [End Date] as parameters for whatever month they are looking for. I tried this query but it doesn't like it.

SELECT tblEM.HookupDate, tblEM.EndDate, IIf([hookupdate]<[Begin Date] And [enddate]>[End Date],[End Date]-[Begin Date],"Test") AS DaysServed
FROM tblEM;


It works up until I ask it to subtract the two parameter values from eachother. Any way to assign those to variables or something like that?

Thanks for your time!

 

Hi,

I think your problem is with the AND in your IIF.

You'll have to use nested IIFs, cuz, there's neither an AND nor is there an OR function in Access.

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
there's neither an AND nor is there an OR function in Access
But there is an AND and an OR operator ...
 
The And is functioning correctly, I just tested it. The part that it is not liking is subtracting the two parameter values. Any other ideas?
 
You may try something like this
PARAMETERS [Begin Date] DateTime, [End Date] DateTime;
SELECT HookupDate, EndDate, IIf(EndDate>[End Date],[End Date],EndDate)-IIf(HookupDate<[Begin Date],[Begin Date],HookupDate) AS DaysServed
FROM tblEM
WHERE HookupDate<[End Date] AND EndDate>[Begin Date];

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


Egg on my face [blush]

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
Thanks PHV! That suggestion worked like a charm!

Merry Christmas and Happy New Year! Have a Star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top