Re: Year comparison
- From: "Matthew" <mcuriale@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 20 Apr 2006 12:20:34 -0400
I'm pretty sure that I've seen it pop up in a couple of the other prg's, so
I'll look out for it.
From what you guys have been answering, I'm almost tempted to just changethe format in the form so that it accepts a 4 digit year, and use that for
the comparison. This bug is going to have me spiralling out of control for
the next few days, I think.
I'll give what you've suggested a try, and see if I can't figure something
out. Any other help would be appreciated.
"Dan Freeman" <spam@xxxxxxxxxxxxx> wrote in message
news:OnQws8IZGHA.3972@xxxxxxxxxxxxxxxxxxxxxxx
To get the last two digits:
Right(Transform(Year(date())),2)
Kinda convoluted, eh? It would still be more readable to use the
four-digit
year. And remember that this makes it a string comparison rather than
numeric so convert the other side as well. Or convert back, making it even
MORE convoluted.
My only caution is that this function you're editing has the look and feel
of a "generic" validation used in many places so any change you make may
affect other behaviors. Make sure you're prepared for that if it is the
case.
Dan
Matthew wrote:
Thanks for the quick response Andrew.
I understand the logic behind this and it makes sense, now it's just
getting my fingers/brain around the code. The user is going to be
entering the date in abbreviated format, ie: 28/07/06. I tried
modifying the code using what you gave me and a substring to extract
the last two numbers of the any_date year, but to no avail. Using
just the line that you provided results in the same error message
popping up.
I think the bug now is getting it to compare in the proper format. Any
suggestions on shaving down the extracted date to the last 2 digits?
As for the aside, I will be making small tweaks to the program. I was
given the program to clean up and make useable before mid-May, so I'm
more worried about the code first before handling the small things.
But yes, from what I learned in my CIS course, I will be changing
those small things around. There's no documentation in the prog
either, so I'm doing a lot of stumbling.
Matt
"Andrew Howell" <ajh@work> wrote in message
news:Oveb7gIZGHA.3848@xxxxxxxxxxxxxxxxxxxxxxx
"Matthew" <mcuriale@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23llaiSIZGHA.3972@xxxxxxxxxxxxxxxxxxxxxxx
I'd been staring at this for a few days, and it finally dawned on
me that there's probably something wrong with the second IF
statement. From the way that I'm interpreting it, it reads: If the
entered date's year does not equal the system date's year, then
display Invalid Year.
Is my assumption correct? And if so, would a simple range check of
You are correct, that's what that line is comparing.
IF ( year( m.any_date ) < 05 .OR. year(m.any_date ) > 99 )
*display error message
No, YEAR() returns 4 digit years, you'd want to use 2005 and 2099,
it may look cleaner to write
IF !BETWEEN(YEAR(m.any_date), 2005, 2099)
* error message
ENDIF
but you've altered the validation considerably.
clear up this annoyance? If not, what would be a cleaner/easier way
to check to see if the date entered is valid or not?
I think the first question is how should it be validated (in
English)? Apparently not by checking against the system date's year
because it's blown up doing that already. Maybe the users are
needing to enter last year's exams at the beginning of a year or
next year's exams at the end, in which case you could use something
like
IF !BETWEEN(YEAR(m.any_date), YEAR(DATE())-1, YEAR(DATE())+1)
* error message
ENDIF
As an aside, it is kinder to the user to describe why the date is
invalid so maybe you want to reword the error message whilst you're
in there too.
--
Regards
Andrew Howell
.
- Follow-Ups:
- Re: Year comparison
- From: Dan Freeman
- Re: Year comparison
- References:
- Year comparison
- From: Matthew
- Re: Year comparison
- From: Andrew Howell
- Re: Year comparison
- From: Matthew
- Re: Year comparison
- From: Dan Freeman
- Year comparison
- Prev by Date: Re: Function sequence error
- Next by Date: Re: Year comparison
- Previous by thread: Re: Year comparison
- Next by thread: Re: Year comparison
- Index(es):
Relevant Pages
|