473,387 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Two Digit Year

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
12 42663
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
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
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
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
"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
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
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
"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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: middletree | last post by:
I have a field that is stored in SQL Server in date/time format. On one page, I only need the date to display. I am able to do this by saying: DateValue(strLastModified) However, this returns...
2
by: John Baker | last post by:
Hi: I need to set the standard for our Approach application that dates are always displayed with a 4 digit year. I cant find the place in Approach where this can be set, since all the formats...
5
by: MHenry | last post by:
Hi, I don't know what happened, but all the MS Access dates in all tables, queries, forms, and reports in all databases suddenly show on my computer with the year as 4 digits (including network...
0
by: Panayotis Kouvarakis | last post by:
I have noticed that CompareValidator and RangeValidator don't work properly with 2-digit year dates when using client script validation. Specifically the problem lies in the way the string is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.