John, you're just naturally sneaky! So, the "zeroth" day of the month
is the last day of the previous month. So what is the -1th day of the
month? Last Thanksgiving?
The only problem would be if Microsoft ever "fixes" the function so it
doesn't do this anymore. Hopefully that won't happen, but if you
"misuse" a function like this (and that's a judgement call) and they
later "fix" it, then a lot of queries are going to stop working.
I would tend to recommend not using a "trick" method because of this
danger. I have enough things to fix in order to get my applications
working in Access 2003 without having to worry about such things. But
everyone should decide for themselves (and be prepared to face the
consequences).
Although it's messier, I'll stick with the alternative I posted. But
your suggestion is tempting. I like tricky things, too!
So what is the zeroth month of the year? Are there any values for
month and day that result in DateSerial eventually blowing up?
And how do you know that this undocumented feature never fails? Will
you be calling Microsoft to complain that DateSerial is broken because
it doesn't do this odd behavior in some particular case? Good luck!
(I believe John know me well enough to know I don't mean any of this
in an unfriendly manner.)
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
I am attempting to create a query that will give me...
the last date of the previous month
the last date of the current month.
My application is for use in tracking mileage and maintenance on a fleet of vehicles. My Maintenance table is set up with fields that include
ID, MaintDate,OdometerRead.
I'm close, I'm sure, but am stumped!
Help, if you can.
There's a sneaky way to use the DateSerial function for this purpose.
The last day of a month is the zeroth day of the *next* month:
LastDayPrevious: DateSerial(Year([MaintDate]), Month([MaintDate]), 0)
LastDayCurrent: DateSerial(Year([MaintDate]), Month([MaintDate])+1, 0)