Short date format

N

narfla

When I enter a birthdate that is prior to 1925, the display is 20.. instead
of 19.. I would like to make the default year 1901. For instance, if I
enter 2/2/02, the display should be 2/2/1902 insteand of 2/2/2002.
Thanks for any help you may render.

narfla
 
A

Arvin Meyer [MVP]

Try enterin the year as 4 digits. The problem you are having is how a DLL
sets the dates for entries of 2 digits. Changing it, changes it for
everything on the computer. Right now the date of century change is 2029.
That can be altered in Control Panel >>> Regional Settings >>> Regional >>>
Customize
 
F

fredg

When I enter a birthdate that is prior to 1925, the display is 20.. instead
of 19.. I would like to make the default year 1901. For instance, if I
enter 2/2/02, the display should be 2/2/1902 insteand of 2/2/2002.
Thanks for any help you may render.

narfla

Since Year 2K, Windows/Office will assume any entered 2 digit year
between 00 and 29 as 2000 to 2029.
Any 2 digit year entered between 30 and 99 will be assumed to be 1930
to 1999.
You'll have to enter a 4 digit year, not a 2 digit year, so that
Windows won't have to assume.
 
J

John W. Vinson

When I enter a birthdate that is prior to 1925, the display is 20.. instead
of 19.. I would like to make the default year 1901. For instance, if I
enter 2/2/02, the display should be 2/2/1902 insteand of 2/2/2002.
Thanks for any help you may render.

narfla

I agree with Arvin and Fred that the best solution would be to use four digit
years - at some point you will need to enter 21st century birthdates! Are you
designing your own private Y2K bug?

Well... if you are... one way to do this would be to do all your data entry
using a Form; in the date of birth textbox's AfterUpdate event put code like

Private Sub txtDOB_AfterUpdate()
If Me!txtDOB > #1/1/2000# Then
me!txtDOB = DateAdd("yyyy", -100, Me!txtDOB)
End If
End Sub
 
G

gllincoln

Hi Narfla,

If you use short date conventions then you are stuck with that by default,
unless you want to refigure the computer entirely.

An alternative would be to create an event procedure to impose your own
rules for birthdate.

We can safely assume that the birthdate is not a day in the future. We can
make anything newer than 2000 step back a century but what if you hit a date
where you need something between 2001 and Now to appear? If we hardcode the
shift, that isn't going to be an option. There is one alternative - we code
for a special date - 1/1/01 seems a good choice. If you enter 1/1/01 then
we pop up an inputbox and ask you to enter the date in the MM/DD/YYYY (four
digit year) format. Whatever you enter in the input box is what will be
recorded if it is a valid date- even if it makes no sense 12/31/2999 for
example, so the person using the 1/1/01 switch needs to understand how this
works, why it's there, and how it should be used.

Note: this code could flake if the preceding century wasn't a leap year -
this has no effect on your usage because we are keeping 2000 as 2000, but if
someone else uses a similar brute force function to manhandle dates over a
different, longer time span, then they need to deal with the Gregorian
calendar rules. If the century marker (1900,2000,2100) is divisible by 400
(year 200 for instance)), then it's a leap year, otherwise no.

I will call the text box txtBirthDay

We can create and use a function to do this, so that we can reuse the
functionality elsewhere if the occasion arises.

in the after update event - we could do this

Me!txtBirthDay = ShiftDate(me!txtBirthDay)

And then add this function to the form code or a module

Public Function ShiftDate(ByVal d As Date) As Date

Select Case d

Case Is = #1/1/2001#
ShiftDate = InputBox("Enter the Birth Date in MM/DD/YYYY
format", "Birth Date")
Case Is > #1/1/2001#
ShiftDate = CDate(Format(d, "MM/DD/") & "19" & Format(d, "YY"))
Case Else
ShiftDate = d

End Select

End Function
=============================

Or we could embed the code in the afterupdate event of the control this way.

Select Case Me!txtBirthDay
Case Is = #1/1/2001#
Me!txtBirthDay = InputBox("Enter the Birth Date in
MM/DD/YYYY format", "Birth Date")
Case Is > #1/1/2001#
Me!txtBirthDay = CDate(Format(d, "MM/DD/") & "19" &
Format(d, "YY"))
Case Else
'do nothing
End Select


=============================

Hope this helps...

Gordon
 
Top