Year(Now()) issues

  • Thread starter Thread starter tom mcnally
  • Start date Start date
T

tom mcnally

'Splain this to me (in AccessXP):
1. Year(Now())=2003 (sometimes I get an object type error
message when trying to assign this result to an integer
or long or variant variable, so have tried following)
2. CStr(Year(Now()))='2003' (usually works but depends
upon the
3. Format(Year(Now()),"yyyy")=1903 (!)
4. Format(Year(Now()),"####")=2003

#3 happens on virtually every XP Prof/XP Office PC I work
on, which are all configured pretty much the same, SP1
applied and all the latest service packs.
 
tom said:
'Splain this to me (in AccessXP):
1. Year(Now())=2003 (sometimes I get an object type error
message when trying to assign this result to an integer
or long or variant variable, so have tried following)
2. CStr(Year(Now()))='2003' (usually works but depends
upon the
3. Format(Year(Now()),"yyyy")=1903 (!)
4. Format(Year(Now()),"####")=2003

#3 happens on virtually every XP Prof/XP Office PC I work
on, which are all configured pretty much the same, SP1
applied and all the latest service packs.

The Year function returns a variant of type integer, so,
this year, Year(Now()) is definitly going to be 2003.

But, the format "yyyy" expects a date type value, not an
integer. Since the integer 2003 is equivalent to the date
6/25/1905, Format(Year(Now()),"yyyy") should return "1905".
You could just use Format(Date, "yyyy") to get the string
"2003".

Note that you may not want to use Now() since it include a
time value, the Date() function might be more appropriate.
 
Thanks, Marshall! This has boggled my overtaxed mind for
too long. I'll make the change to Date rather than Now.
(and the year was 1905 not 1903)

Tom
 
Back
Top