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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateSerial Calculation as Parameter 1

Status
Not open for further replies.

zoroaster

Programmer
Jun 10, 2003
131
GB
Hi all

Trying to create a parameter based on Today's Date, so the query looks at Dates in the table from: The start of the month a year ago, to the end of last month. i.e. Today's date happens to be 21st Sept 04, so I want to return From:1st Sept 03, To:31st Aug 04. I've been playing with DateSerial, but getting unexpected results. Here are the expressions I'm using:

From: DateSerial(Year(Date())-1,Month(Date()),Day(1))

To: DateSerial(Year(Date()),Month(Date())-1,Day(Date()-(Day(Date()+1))))

But instead of getting 1/9/03 and 31/8/04 I'm getting 1/10/03 and 30/8/04

Any ideas?
With thanks

Laters, Z

"42??? We're going to get lynched!
 
hi,
Code:
From = DateSerial(Year(Date) - 1, Month(Date), 1)

Thru = DateSerial(Year(Date), Month(Date), 1) - 1

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Aha
I figured a way of getting the 'To' date: DateSerial(Year(Date()),Month(Date())-1,Day(Date()-(Day(Date())))), but Skip's is simpler and more elegant - simple when you know how!
Thanks Skip!

Laters, Z

"42??? We're going to get lynched!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top