Solved Previous YTD query (1 Viewer)

mkdrep

Registered User.
Local time
Today, 05:46
Joined
Feb 6, 2014
Messages
176
Doing some of my own research, I found the following query which lets me automatically pull up data based on my [DocCreated] date field:
Year([DocCreated])=Year(Date()) And Month([DocCreated])<=Month(Date()) And Day([DocCreated])<=Day(Date())

What sort of modification should I make it I want the previous YTD data to show up based on today's date? In other words, the above query will give me data created thryu 7/27/2020, I'm looking for a query that will show me data for the previous year's same time frame, namely 1/1/2019 to 7/27/2019. Is that possible in Access?

Thank you.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:46
Joined
Feb 19, 2013
Messages
16,553
PrevYear: Year(Date()) -1

or use the dateadd function

YTD - between dateadd("y",-datepart("y",date),date)+1 AND Date
PriorYTD - between dateadd("yyyy",-1,dateadd("d",-datepart("y",date),date))+1 And dateadd("yyyy",-1,date)

note: if your date field includes a time element, then todays records will not appear
 

bob fitz

AWF VIP
Local time
Today, 09:46
Joined
May 23, 2011
Messages
4,717
Perhaps:
Year([DocCreated])=Year(Date()-1) And Month([DocCreated])<=Month(Date()) And Day([DocCreated])<=Day(Date())
 

mkdrep

Registered User.
Local time
Today, 05:46
Joined
Feb 6, 2014
Messages
176
I used your first suggestion and it worked perfectly!
Thank you for the help!
 

Users who are viewing this thread

Top Bottom