Re: Year comparison

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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 change
the 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




.



Relevant Pages

  • Re: Problem with inserting records from Textboxes
    ... i've checked all my fields in the tables and I have not set any validation ... which is in medium date format. ... following similar error message occured. ... Duane Hookom wrote: ...
    (microsoft.public.access.modulesdaovba)
  • Undefined function Right in expression
    ... I am trying to get a 8 digit number string in the ... into a date format. ... The same error message appears for the Mid ...
    (microsoft.public.access.tablesdbdesign)
  • Re: FAQ Topic - How do I format a date with javascript? (2009-06-01)
    ... instead of a YYYY-MM-DD string also works; ... The ISO 8601 Extended format can be understood internationally, ... ISO 8601 Extended formats can be... ... Most inputs will pass validation, so the need is to reach success ...
    (comp.lang.javascript)
  • Re: Common Malware Enumeration Initiative Now Available
    ... CME identifiers will be in the format CME-N where N ... digit number is pretty much likely to never run out. ... vulnerability exploited, prior criminal history, etc... ...
    (microsoft.public.security.virus)
  • Re: Recent word exploit also causes problems in OpenOffice
    ... OpenOffice doesn't even know the intimate details of the format, ... validation is incomplete by import alone, ... Virus scanners are always the combatants of symptoms, they always have been and always will be. ... A memory dump from one program or even program version would be, by definition, incompatible with another program or version. ...
    (alt.computer.security)