Date query - how do I find the last April?

wilsation

Registered User.
Local time
Today, 00:11
Joined
Jul 28, 2014
Messages
44
Hi, I have several queries based around the financial year so they mostly begin in April (01/04). The following code will count all rows in April of the current year, but if I run it in January it obviously returns zero.
Code:
Count(IIf([RTB1] Between "01/04/" & Year(Date()) And "30/04/" & Year(Date()),0))
I know I can add DATE()-1 to go back to the previous year but then if you run it in May it will return results for April the previous year.
So what I need is a way of going back to the last April regardless of the current month.

Thanks
 
Date math is done with DATEADD.
D=day
M=month
Yyyy= year

DAteAdd("yyyy",-1,"30/04/" & year(Date))
 
Code:
DateSerial(Year(Date) + (Month(Date) < 4), 4, 1)

(Month(Date)<4) evaluates as -1 or 0 so if the month is less than April, one year is subtracted.
 
Last edited:
Hi Ranman, so my code should look like this?
Code:
App1: Count(IIf([RTB1] Between DateAdd("yyyy",-1,"01/04/" & Year(Date)) And DateAdd("yyyy",-1,"30/04/" & Year(Date)),0))
When I add it to my query Access adds brackets to the Date like this...
Code:
App1: Count(IIf([RTB1] Between DateAdd("yyyy",-1,"01/04/" & Year([Date])) And DateAdd("yyyy",-1,"30/04/" & Year([Date])),0))
Which obviously doesn't work.

Thanks
 
Got it sorted thanks, used this:
Code:
App1: Count(IIf([RTB1] Between DateAdd("yyyy",-1,"01/04/" & Year(Date())) And DateAdd("yyyy",-1,"30/04/" & Year(Date())),0))
 

Users who are viewing this thread

Back
Top Bottom