Created
December 10, 2017 12:48
-
-
Save sebzur/47f154c315973d4707ce8703adfb354c to your computer and use it in GitHub Desktop.
Extracts date of birth from polish PESEL identifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 | |
import datetime | |
def dob_from_pesel(pesel): | |
# based on http://dev.cdur.pl/Artykuly/Pobieranie-daty-urodzenia-i-plci-z-numeru-PESEL-Javascript | |
year = 1900 + int(pesel[0:2]) | |
if 2 <= int(pesel[2]) < 8: | |
year += (int(pesel[2]) / 2) * 100 | |
if int(pesel[2]) >= 8: | |
year -= 100 | |
month = (int(pesel[2]) % 2) * 10 + int(pesel[3]) | |
day = int(pesel[4:6]) | |
return datetime.date(year, month, day) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment