Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting a 2 digit year to 4 digit year

1,574 views
Skip to first unread message

Anthony Vitelli

unread,
Mar 7, 2002, 12:51:10 PM3/7/02
to
Does anyone have a good way to update a column containing a 2 digit
year, and set it to the corresponding 4 digit year?

Example: 99 is the value in the column, and I want to set it to 1999.

Thanks!

Rick Brandt

unread,
Mar 7, 2002, 1:50:28 PM3/7/02
to
"Anthony Vitelli" <gul...@yahoo.com> wrote in message
news:195b73b1.02030...@posting.google.com...

Is this a Date field or a Character field that contains text representing a
date or year? If the former you should know that Access always stores dates
exactly the same way. What you "see" is only a display format which by
default follows the date format set in your Windows Control Panel. Any
place where the date will be "seen" you can apply any other valid date
format.

If the field contains character data then I would need to know exactly how
the entries are formatted to be able to answer.


Larry Linson

unread,
Mar 7, 2002, 10:44:46 PM3/7/02
to
And what two digit years you want to convert to what four digit years,
definitely. That is, is "20" to be 1920 or 2020?

"Rick Brandt" <RBr...@Hunter.Com> wrote in message
news:a68cpv$cg78n$1...@ID-98015.news.dfncis.de...

Anthony Vitelli

unread,
Mar 8, 2002, 11:53:15 AM3/8/02
to
The field is just a text field, in which there are 2 numeric digits.
They are the last 2 of a year, and I need to convert them to a four
digit year. I was wondering if Access (or VBA) had any cool function
to check a 2 digit year and then expand it to the correct 4 digit
year.

Thanks,

Anthony

"Larry Linson" <larry....@ntpcug.org> wrote in message news:<OsWh8.7675$J3....@nwrddc01.gnilink.net>...

mattalexx

unread,
Mar 8, 2002, 3:20:04 PM3/8/02
to
Based on a two digit year string, there is no way of knowing exactly
which century to place it in (example: "97" = "1997" or "2097"). The
data just doesn't exist.

Here is a code that will only work correctly if the dates are between
1951 and 2050:

fFix(strAbbrev As Integer) as String Dim strCent As Integer If strAbbrev
> 50 Then strCent = 19 If strAbbrev <= 50 Then strCent = 20 fFix =
strCent & strAbbrev End Function

Good luck, Matt(+)

--
Posted via dBforums
http://dbforums.com

Larry Linson

unread,
Mar 8, 2002, 4:35:42 PM3/8/02
to
That was the question... how would Access know whether you want "20" to be
"1920" or "2020"? Access does have a "windowing technique" that it uses, as
you may direct, for converting dates you type in with two-digit years, but
no builtin function for converting the field. It'd be a pretty simple
function, something like this air code:

Function FourYearDate (pstrYear as String) as String

Dim intYear as Integer
If Len(pstrYear) > 0 and Len(pstrYear) < 3 Then
intYear = CInt(pstrYear)
If intYear > 30 Then
FourYearDate = Format(1900 + intYear, "YYYY")
Else
FourYearDate = Format(2000 + intYear, "YYYY")
End If
End If

End Function

You'll need to add your own error handling for the case where the string is
empty or too long, or for an error that CInt might throw if you passed in
"RB" instead of numeric characters.

Larry Linson

unread,
Mar 8, 2002, 4:36:40 PM3/8/02
to
The aircode, if its not obvious, converts two digit years greater than 30 to
19xx, and 30 or less to 20xx.

Вујадин Bасовић

unread,
Apr 24, 2023, 9:01:04 AM4/24/23
to
Hi. What about 2023
0 new messages