By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

Two Digit Year

P: n/a
I feel embarassed asking such a simple question ---

Year(Date()) returns 2004; I want only the last two digits.
Format(Year(Date()),"yy") returns 05. How do I get 04?

Thanks!

Mark
Nov 12 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
myYear = Right(Year(Date()), 2)
--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access
"Mark" <mm*****@earthlink.net> wrote in message
news:f1*******************@newsread3.news.atl.eart hlink.net...
I feel embarassed asking such a simple question ---

Year(Date()) returns 2004; I want only the last two digits.
Format(Year(Date()),"yy") returns 05. How do I get 04?

Thanks!

Mark

Nov 12 '05 #2

P: n/a
I just checked it and mine does the same thing. It appears to be a bug. I'll
pass it on. As a work-around, Jerry's suggestion should work.

--
Wayne Morgan
Microsoft Access MVP
"Mark" <mm*****@earthlink.net> wrote in message
news:f1*******************@newsread3.news.atl.eart hlink.net...
I feel embarassed asking such a simple question ---

Year(Date()) returns 2004; I want only the last two digits.
Format(Year(Date()),"yy") returns 05. How do I get 04?

Nov 12 '05 #3

P: n/a
Disregard my previous message, I couldn't see the forest for the trees.

Format(Date(), "yy") should give you the correct answer. The problem is the
Year(Date()) isn't a date, it is an integer. Access/VBA handles dates as
integers. 2004 would give you a date 2004 days after VBA's root date which
happens to be a day in 1905.

--
Wayne Morgan
Microsoft Access MVP
"Mark" <mm*****@earthlink.net> wrote in message
news:f1*******************@newsread3.news.atl.eart hlink.net...
I feel embarassed asking such a simple question ---

Year(Date()) returns 2004; I want only the last two digits.
Format(Year(Date()),"yy") returns 05. How do I get 04?

Thanks!

Mark

Nov 12 '05 #4

P: n/a
What about Format(now(), "yy")?

Strange though - they both work yield 04 for me in A-2K and A-XP in the
immediate window doing...

?Format(now(), "yy")
or
?Format(date(), "yy")
--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:KO*******************@newssvr31.news.prodigy. com...
Disregard my previous message, I couldn't see the forest for the trees.

Format(Date(), "yy") should give you the correct answer. The problem is the Year(Date()) isn't a date, it is an integer. Access/VBA handles dates as
integers. 2004 would give you a date 2004 days after VBA's root date which
happens to be a day in 1905.

--
Wayne Morgan
Microsoft Access MVP
"Mark" <mm*****@earthlink.net> wrote in message
news:f1*******************@newsread3.news.atl.eart hlink.net...
I feel embarassed asking such a simple question ---

Year(Date()) returns 2004; I want only the last two digits.
Format(Year(Date()),"yy") returns 05. How do I get 04?

Thanks!

Mark


Nov 12 '05 #5

P: n/a
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:KO*******************@newssvr31.news.prodigy. com:
Access/VBA handles dates as integers.


I think VBA handles dates as dates.
no ... not as doubles.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #6

P: n/a
That's what I thought. When I convert integers, I add them to whatever the
begin date for the language starts at... for instance, this is for finding
the date for Professional Basic (1/1/1980)...

myDate = DateAdd("d", iDays, "1/1/1980")

I would think that it returning 05 would have more than likely been for
todays day - 1..."05"....2004, but don't know how that worked out, unless
Mark mistyped the problem.

--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:KO*******************@newssvr31.news.prodigy. com:
Access/VBA handles dates as integers.


I think VBA handles dates as dates.
no ... not as doubles.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #7

P: n/a
In the immediate window try

?Format(0,"Long Date")
Saturday, 30 December 1899
(this is the base date)

The date portion is the integer part and the time (fraction of a day) is the
decimal portion. So

?Format(2004, "Long Date")
Monday, 26 June 1905

or 2004 days after 30 Dec 1899.

That is why you can simply add a number to a date to get another date.

?#3/1/2004#+3
3/4/2004

--
Wayne Morgan
Microsoft Access MVP
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:KO*******************@newssvr31.news.prodigy. com:
Access/VBA handles dates as integers.


I think VBA handles dates as dates.
no ... not as doubles.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #8

P: n/a
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:ND******************@newssvr33.news.prodigy.c om:
That is why you can simply add a number to a date to get another date.


But is it the right date?

--------------------------------------------------

?format(#12/30/1899#+(-0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

?format(#12/30/1899#+(0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

Can adding (-0.5) give the same result as adding (0.5)?

Dates is dates.

And if we want to subtract 1/2 a day from a date it may be better to use
DateAdd and the long count of a date time interval.

---------------------------------------------------

?format(DateAdd("h",(-12), #12/30/1899#),"\#mm\/dd\/yyyy hh:nn")
#12/29/1899 12:00

---------------------------------------------------

from the help file:
"If number [in DateAdd(interval, number, date)] isn't a Long value, it is
rounded to the nearest whole number before being evaluated."
My experience (not very much) is that number is truncated, not rounded.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #9

P: n/a
The problem appears to be that you've hit the limit because this is the base
date. It doesn't want to go back beyond that to the 29th.

?format(#12/31/1899#+(0.5),"mm\/dd\/yyyy ttttt")
12/31/1899 12:00:00 PM

?format(#12/31/1899#+(-0.5),"mm\/dd\/yyyy ttttt")
12/30/1899 12:00:00 PM

As you can see, if I move up to the 31st and try the same thing, it works.

--
Wayne Morgan
Microsoft Access MVP
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:ND******************@newssvr33.news.prodigy.c om:
That is why you can simply add a number to a date to get another date.


But is it the right date?

--------------------------------------------------

?format(#12/30/1899#+(-0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

?format(#12/30/1899#+(0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

Can adding (-0.5) give the same result as adding (0.5)?

Dates is dates.

And if we want to subtract 1/2 a day from a date it may be better to use
DateAdd and the long count of a date time interval.

---------------------------------------------------

?format(DateAdd("h",(-12), #12/30/1899#),"\#mm\/dd\/yyyy hh:nn")
#12/29/1899 12:00

---------------------------------------------------

from the help file:
"If number [in DateAdd(interval, number, date)] isn't a Long value, it is
rounded to the nearest whole number before being evaluated."
My experience (not very much) is that number is truncated, not rounded.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #10

P: n/a
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:_J******************@newssvr31.news.prodigy.c om:
The problem appears to be that you've hit the limit because this is the
base date. It doesn't want to go back beyond that to the 29th.

?format(#12/31/1899#+(0.5),"mm\/dd\/yyyy ttttt")
12/31/1899 12:00:00 PM

?format(#12/31/1899#+(-0.5),"mm\/dd\/yyyy ttttt")
12/30/1899 12:00:00 PM

As you can see, if I move up to the 31st and try the same thing, it
works.


sigh ...

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #11

P: n/a
http://support.microsoft.com/default...b;en-us;210276

--
Wayne Morgan
MS Access MVP
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...

sigh ...

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #12

P: n/a
Lyle,

I had to ask about this one, but got an answer.

Since the integer portion is the day and the decimal is the time and 30
December 1899 is day zero what you get by subtracting .5 from 0 is -0.5.
This is still day 0 (the integer portion) so you still get 30 Dec 1899. You
have to go to -1 to get 29 Dec 1899. In other words, there is no difference
between -0 and +0, they are the same number. The date handling breaks the
number apart into its 2 components, the integer and the decimal, and then
gives the result. The mathematics though, is performed as expected. So, the
number is being treated differently by the date conversion than it is by the
math routines.

So you have found a place that simply adding and subtracting instead of
using DateAdd or other functions may cause problems. However, in the dates
most people deal in, this probably won't show up.

--
Wayne Morgan
Microsoft Access MVP
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"Wayne Morgan" <co***************************@hotmail.com> wrote in
news:ND******************@newssvr33.news.prodigy.c om:
That is why you can simply add a number to a date to get another date.


But is it the right date?

--------------------------------------------------

?format(#12/30/1899#+(-0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

?format(#12/30/1899#+(0.5),"\#mm\/dd\/yyyy hh:nn")
#12/30/1899 12:00

---------------------------------------------------

Can adding (-0.5) give the same result as adding (0.5)?

Dates is dates.

And if we want to subtract 1/2 a day from a date it may be better to use
DateAdd and the long count of a date time interval.

---------------------------------------------------

?format(DateAdd("h",(-12), #12/30/1899#),"\#mm\/dd\/yyyy hh:nn")
#12/29/1899 12:00

---------------------------------------------------

from the help file:
"If number [in DateAdd(interval, number, date)] isn't a Long value, it is
rounded to the nearest whole number before being evaluated."
My experience (not very much) is that number is truncated, not rounded.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.