calculate Age problem date notation european american format

F

feorges

Hi,
in a module i want to calculate the age of a person , When a person is less
than 1 year, i will count the months.
My problem is that on user will gives dates in european format (dd-MM-yyyy)
and the code alwayes calculate in american notation with a mismatch as
result. A person which is born on 05-01-2010 (dd-MM-YYYY) will be born in
code on the first of mai (MM-dd-yyyy). in this example the peron is must one
year and 3 months, in code he wil be less than one year and he is only 11
months old.
How i can solve this problem ?

kindley regards Georges
 
B

Bob Barrows

feorges said:
Hi,
in a module i want to calculate the age of a person , When a person
is less than 1 year, i will count the months.
My problem is that on user will gives dates in european format
(dd-MM-yyyy) and the code alwayes calculate in american notation with
a mismatch as result. A person which is born on 05-01-2010
(dd-MM-YYYY) will be born in code on the first of mai (MM-dd-yyyy).
in this example the peron is must one year and 3 months, in code he
wil be less than one year and he is only 11 months old.
How i can solve this problem ?
Use a calendar control for date entry and store the dates in a date/time
column rather than a text column.
 
J

John W. Vinson

Hi,
in a module i want to calculate the age of a person , When a person is less
than 1 year, i will count the months.
My problem is that on user will gives dates in european format (dd-MM-yyyy)
and the code alwayes calculate in american notation with a mismatch as
result. A person which is born on 05-01-2010 (dd-MM-YYYY) will be born in
code on the first of mai (MM-dd-yyyy). in this example the peron is must one
year and 3 months, in code he wil be less than one year and he is only 11
months old.
How i can solve this problem ?

kindley regards Georges

A Date/Time field has no formatting. It's actually stored as a number, a count
of days and fractions of a day since midnight, December 30, 1899.

The code needs to use the DateValue() function to convert the user's input to
a valid Date/Time. DateValue() recognizes the computer's regional date
settings; thus someone whose computer is set to the American m/d/y setting
will see 3/5/2010 as March 5, whereas a computer set to European dates will
see it as May 3.

So just use an expression such as

DateValue([Forms]![yourform]![controlname])

in your age calculation and you should be ok regardless of the user's regional
setting.

However, if you have a computer with its Control Panel... Regional and
Language Settings... Regional set to "English (US)", and the user sitting in
front of it types a date in European order, it will obediently give the wrong
answer. One suggestion is to avoid the ambiguity by either training the users
to use the ISO yyyy-mm-dd format (2011-04-14) or use the month name (Apr 14 or
14 Apr).
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top