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!

How return a year ago from date?

Status
Not open for further replies.

supportservice

Technical User
Mar 12, 2012
63
What is the best way to replace the 366 days ago, as some months it might be 367, etc ... (31 days vs 30 Days, and Feb. with 28 or 29 days) to return a year ago from the date selected on the FromDate?

Code:
 (IIf([PostingDate] Between Forms!DateSelector!FromDate-366 And Forms!DateSelector!ToDate-366,([CreditAmount])-[DebitAmount],0))
 


A year ago...
Code:
DateSerial(Year([Your Date])-1, Month([Your Date]), Day([Your Date]))


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thank you but ...
That returns all of last year?

Code:
 Between #4/1/2012#-DateSerial(Year([PostingDate])-1,Month([PostingDate]),Day([PostingDate]))

I am would like this to return, from 4/1/2012, last year up to 3/31/2011.
Not sure how to do that?
 
what is the value of [PostingDate]?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Code:
 LMTD: (IIf([PostingDate] Between [Forms]![DateSelector]![FromDate]-DateSerial(Year([PostingDate])-1,Month([PostingDate]),Day([PostingDate])) And [Forms]![DateSelector]![ToDate]-DateSerial(Year([PostingDate])-1,Month([PostingDate]),Day([PostingDate])),[Amount],0))

Noting that FromDate=4/1/2012 and ToDate=4/30/2012
Need to return data from 1/1/2011 through 4/1/2011 and 1/1/2011 through 4/30/2011
 


Well THAT is NOT what you asked for! Please ask what you mean and draw inference.

The first of the year is
Code:
DateSerial(Year([Your Date]), 1, 1)


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip,
Yes, I apologize. Trying to write it out to make sense and convey what I am looking for help in.
Forget the above.

Here is what I have:
[PostingDate] Between [Forms]![DateSelector]![FromDate]-366 And [Forms]![DateSelector]![ToDate]-366

Say the parameters are set to: FromDate = 4/1/2012 and ToDate = 4/30/2012

I need to return data from 1/1/2011 through 4/1/2011 and 1/1/2011 through 4/30/2011

Hope that makes more sense?
 


Well then you have the information that you need.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Using
Between DateSerial(Year([Forms]![DateSelector]![FromDate])-1,1,1) And DateSerial(Year([Forms]![DateSelector]![ToDate])-1,1,1)

Where FromDate = 4/1/2012 and ToDate = 4/30/12

It's only returning 1/1/2011, which guess makes sense since the DateSerial is to return beginning of the year.

I am expecting it to return 4/1/2011-4/30/2011

So am not sure how to have it return 4/1/2011 - 4/30/2011 and 4/1/2012 - 4/30/2012 are selected?
 

You seem very confused, disoriented, befuddled and bewildered.

Your queries and responses seem unrelated.

Frankly, you have perplexed me.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I am.

Try from the top.

I currently have:

FromDate = 4/1/2012
ToDate = 4/30/2012

I have: Between Forms!DateSelector!FromDate-366 And Forms!DateSelector!ToDate-366

This gives me data for 4/1/2011 through 4/30/2011, exactly what I need.

----
HOWEVER, in May there are 31 days so the -366 days from the date selection won't be accurate.

I am trying to replace the 366 days so it'll always return the selected month range from the DateSelector for the prior year.

Hope that made better sense. I thought that is what I was asking.

Anyway, to be clear I do not need to know the beginning of the year but rather the prior year based on the date selected, which will always be the current year's month range that are entered.
 
How many different ways of asking that until it's understood is unsure. I don't know how else to ask the question.
 
Simplifying it to

How to get 4/1/2011 through 4/30/2011 data returned when the user enters 4/1/2012 through 4/30/2012?

Basically need to know the prior year's data for the date selected, which will always be the current year.
 


I just reread your last post. You have been all over the place!

It is the first time that you stated that you wanted a critera from Year To Date CURRENT year and Year To Date of the PREVIOUS year. I summarily dismissed you because you previously specified nonsense.

So here is what it seems you have stated for the first time...
Code:
where [SomeDate] Between DateSerial(Year([Forms]![DateSelector]![FromDate])-1,1,1) And DateSerial(Year([Forms]![DateSelector]![ToDate])-1, Month([Forms]![DateSelector]![ToDate]), Day([Forms]![DateSelector]![ToDate]))

  OR [SomeDate] Between DateSerial(Year([Forms]![DateSelector]![FromDate]),1,1) And [Forms]![DateSelector]![ToDate]


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Ok thank you.

The first line returns 1/1/2011 - 4/30/2011

So much closer now.

How do I limit it to be from 4/1/2011 to 4/30/2011?

As noted, need it to be the prior year's month range from the selected month range.

Selected 4/1/2012 - 4/30/2012
Return 4/1/2011 - 4/30/2011
 


I have given you numerous examples of using the DateSerial(), Year(), Month() & Day() functions, and two where clause criteria.

If you cannot subsequently craft a solution and TEST and modify as required, you probably need to hire professional help.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top