Age and gender from yyddmm-xxxx

M

Monika Bjurman

I've been searching here and on other places on the Internet but I just can't
find a solution to how to calculate age and gender from swedish
"personnummer" (yymmdd-xxxx where the first two xx is birth location, the
third is gender where 0,2,4,6,8 is female and 1,3,5,7,9 is male).

I keep finding answers for Excel but not for Access so I hope you can help me.
 
A

Allen Browne

You should be able to get a real date/time field by typing an expression
like this in the Field row in query design:
DateSerial(Left([d],2, Mid([d],3,2) Mid([d],5,2))
replacing the d with your field name.

For information about calculating the age, see:
http://allenbrowne.com/func-08.html
 
L

Linq Adams via AccessMonster.com

For the gender part:

If mid(YourPersonnummerFieldName, 10,1) mod 2 = 0 then
Me.Gender = "Female"
Else
Me.Gender = "Male"
End If

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
L

Linq Adams via AccessMonster.com

Or, in the Query Grid

Gender: iif(mid([YourPersonnummerFieldName], 10,1) mod 2 = 0,"Female",
"Male")

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
M

Monika Bjurman

Thank you! You and your homepage solved my problem. I'll post my code
translated to the swedish syntax for other swedes to se if they have the same
problem some other time.

Mitt personnummer var skrivet som ååååmmdd-xxxx i fältet Personnr.

I en fråga skapade jag ett nytt fält under namnet Datum_från_Personnr.

Datum_från_Personnr:
DatumSerie(Vänster([Personnr];2);Mitt([Personnr];3;2);Mitt([Personnr];5;2))

Sen skapade jag ett nytt fält som beräknade åldern beroende på om de redan
fyllt år eller skulle fylla senare under året.

Ålder: Heltal(DatumDiff("å";[Datum_från_Personnr];Datum())/365,25)

Hoppas detta kan vara till hjälp.

mvh
//Monika

Allen Browne said:
You should be able to get a real date/time field by typing an expression
like this in the Field row in query design:
DateSerial(Left([d],2, Mid([d],3,2) Mid([d],5,2))
replacing the d with your field name.

For information about calculating the age, see:
http://allenbrowne.com/func-08.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Monika Bjurman said:
I've been searching here and on other places on the Internet but I just
can't
find a solution to how to calculate age and gender from swedish
"personnummer" (yymmdd-xxxx where the first two xx is birth location, the
third is gender where 0,2,4,6,8 is female and 1,3,5,7,9 is male).

I keep finding answers for Excel but not for Access so I hope you can help
me.
 
M

Monika Bjurman

Thanks, this was exactly what I was looking for. :) I'll add your solution
with swedish syntax for other swedish people to se.

Kön: OOM(Mitt([Personnr];10;1) Mod 2=0;"Kvinna";"Man")

mvh
//Monika
 
J

John W. Vinson

Thank you! You and your homepage solved my problem. I'll post my code
translated to the swedish syntax for other swedes to se if they have the same
problem some other time.

Mitt personnummer var skrivet som ååååmmdd-xxxx i fältet Personnr.

I en fråga skapade jag ett nytt fält under namnet Datum_från_Personnr.

Datum_från_Personnr:
DatumSerie(Vänster([Personnr];2);Mitt([Personnr];3;2);Mitt([Personnr];5;2))

Sen skapade jag ett nytt fält som beräknade åldern beroende på om de redan
fyllt år eller skulle fylla senare under året.

Ålder: Heltal(DatumDiff("å";[Datum_från_Personnr];Datum())/365,25)

Hoppas detta kan vara till hjälp.

Just out of curiosity - what use does Sweden make of this personnummer? It's
not unique, obviously - it allows for five people of each gender to be born on
the same date in the same location, but I'm sure that a busy hospital in
Stockholm will have more than five girls born on any given day!
 
M

Monika Bjurman

You are so right. My informations was 18 years old (probably from high school
;-) ). Today the first three digits are some kind of serial number but the
last of those three digits still tell the sex of the person. The fourth digit
is a control number that you can figure out yourself based on the other 9
digits - mostly to check for missprints.

But yes, the personnummer is unique. Earlier there wasn't just one number
for each town or area. Stockholm - for example - hade numbers from 00 to 13.

//Monika

John W. Vinson said:
Thank you! You and your homepage solved my problem. I'll post my code
translated to the swedish syntax for other swedes to se if they have the same
problem some other time.

Mitt personnummer var skrivet som ååååmmdd-xxxx i fältet Personnr.

I en fråga skapade jag ett nytt fält under namnet Datum_från_Personnr.

Datum_från_Personnr:
DatumSerie(Vänster([Personnr];2);Mitt([Personnr];3;2);Mitt([Personnr];5;2))

Sen skapade jag ett nytt fält som beräknade åldern beroende på om de redan
fyllt år eller skulle fylla senare under året.

Ålder: Heltal(DatumDiff("å";[Datum_från_Personnr];Datum())/365,25)

Hoppas detta kan vara till hjälp.

Just out of curiosity - what use does Sweden make of this personnummer? It's
not unique, obviously - it allows for five people of each gender to be born on
the same date in the same location, but I'm sure that a busy hospital in
Stockholm will have more than five girls born on any given day!
 

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