MS Access: Using a Date Between a Start Date and End Date for a Query - ms-access

Question: Create a query that shows a listing of all kennels that were occupied on February 14, 2015.
So what I have is the Kennel ID, Start Date (of being in a kennel) and End Date (of being in the kennel)
I'm not sure how I am supposed to extract the date February 14, 2015 from being in between Start Date and End Date.
Any help will be appreciated

There are a number of ways of querying this depending on your end goal.
Have a read here for a good visual representation of how to get the results http://www.baldyweb.com/OverLap.htm
In a simple query hard coded to one date this would equate to Criteria like
[End Date] >= #02/14/2017# AND [Start Date] <= #02/14/2017#

Related

How To: Build MS Access query to return date of 2nd Saturday from Current Date?

I'm trying to build a query or VBA code (which ever works best) to return the date for the 2nd Saturday from the current date.
Example: Today is Friday, February 3rd, 2023 (02/03/23). The automatic query should return Saturday, February 11th. This would be calculating the firstdayofweek argument used in the WEEKDAY Function (used in MS Excel and Access) based on the current date.
I've just not been able to build the correct query where it calculates this specific date in time based on the current date.
Any help would be greatly appreciated!
Thanks,
Matt
The structure is going to be '15 days after the friday before today' (originally I thought '14 days after the saturday before today', but that misfires if called on saturdays)
In VBA:
Function SecondSat(Optional DateFrom As Date) As Date
If DateFrom = 0 Then DateFrom = Date 'default to today's date
SecondSat = DateFrom - DatePart("w", DateFrom, vbSaturday) + 15
End Function
in MS Access query language:
SELECT Date() - DATEPART('w', Date(), 7) + 15
You can use my generic function DateNextWeekday found in my library at GitHub: VBA.Date
In code:
NextNextSaturday = DateAdd("ww", 1, DateNextWeekday(Date, vbSaturday))
In a query:
NextNextSaturday: VDateAdd("ww",1,DateNextWeekday(Date(),7))

Access expression, add one year, minus a day

I have a table in access, which has a contract start date, contract end date.
It also needs auto filled columns for the start and end date of each year between the contract start and end dates.
E.g, customer takes out 5 year contract.
01/01/2020 - 01/01/2025
Year 1’s end date would be 1 year, minus a day from the contract start date:
31/12/2020.
As mentioned, this needs to be written as an expression in Microsoft Access.
I can’t find info on multiple date calculations from a singular start date (DateAdd etc).
Thanks for any help
Use DateAdd in code (or query):
UltimoYear = DateAdd("d", -1, DateAdd("yyyy", 5, DateStart))
Replace 5 with 1 for one year.

access query that returns records for previous year up to same day, same month as today but for previous year

I need help specifying an access criteria on a date field that would pull records from my database from the beginning of last year, 1/1/2014 to a date that has the same day, and same month as today. The reason for this information is to be able to able to compare year-to-date records(and later counts) for this year to year-to-date's count for last year... thus, if today's date is 8/20/2015, I would want to be able to pull from 1/1/2015 to 8/20/2015 and then compare it to 1/1/2014 to 8/20/2014.
Just for heads-up, I am using the same query and form to count records based on weekly, quarterly date-ranges, and so I cannot use textboxes with "Start" and "End" dates. Also, I cannot pre-specify any date in my query. Any idea will be greatly appreciated. Thank you all.
To get last year's year-to-date DateSerial will do what you want.
Where [DateColumn] >= DateSerial(year(now)-1,1,1)
and [DateColumn] <= DateSerial(year(now)-1,month(now),day(now))
Another option
Where [DateColumn] >= dateadd("yyyy", datediff("yyyy", 0, now)-2, 2 )
and [DateColumn <= DateAdd("yyyy",-1, now)
You need to use Date() in SQL:
Where [DateColumn] >= DateSerial(Year(Date())-1,1,1)
And [DateColumn] <= DateAdd("yyyy",-1,Date())
The following expression can be used as the criteria for the date field in the query designer
>="01/01/" & (Year(Date())-1) AND <=Day(Date()) & "/" & Month(Date()) & "/" & Year(Date())-1
Warning: using strings to build dates should be avoided when possible. DateSerial() is a better approach, but this will work in MS Access (Jet/ACE).

Datediff function adds startdate day also to the output

I have a report in Report Builder 1.0 wherein I have written a formula that calculates the number of days between startdate and enddate. For that I have used a DATEDIFF function in such a manner:
DATEDIFF(DAY, TODAY(), column from table which has end date)
Suppose, if today's date is 1 July 2013 & the column is sending end date as 10 July 2013, then the DATEDIFF function is returning "10 days" whereas it should return output as value "9 days". Why is it returning 10 days rather than 9?
Execute this in Sql Server and you get 9 days:
select DATEDIFF(day, '2013-07-01', '2013-07-10')
Using this as a dataset:
select CAST('2013-07-01' AS DateTime) AS StartDate, CAST('2013-07-10 23:59:59' AS DateTime) AS EndDate
then using this expression in SSRS:
=DateDiff(DateInterval.Day, Fields!StartDate.Value, Fields!EndDate.Value)
still yields 9 days, even when using a time component. Try the following expression:
=DateDiff(DateInterval.Day, DateTime.Today, Fields!EndDate.Value)
Are you displaying the date fields to make sure what you think you should get is what you actually get? For instance, make sure you aren't being returned cached data.

ms access annual criteria

I need to create a query criteria to get any date from the last 1 may of last year till today, example if I run the query now it should get the data from 1 may 2012 till today, if I run the query the next year on Feb 2013 then get the data from 1 May 2012 till feb 2013.
update
I have used the below as the [JOINED DATE] query criteria but it returns nothing, what is wrong with this?
IIf(Month([Data]![JOINED DATE])>=5,Between DateSerial(Year(Now()),5,1) And Now(),Between DateSerial(Year(Now())-1,5,1) And Now())
Your syntax is incorrect, I do not advise including the "between" keyword in the IIF statement, you want your IIF to only return the date, something like:
SELECT *
FROM A
WHERE A.Date BETWEEN IIf(Month([Joined Date])>=5,DateSerial(Year(Date()),5,1),DateSerial(Year(Date())-1,5,1) AND Date()
Note: I have used Date() rather than Now() as Now() includes the timestamp which is not necessary in this case.