Skip to content

Instantly share code, notes, and snippets.

@sebzur
Created December 10, 2017 12:48
Show Gist options
  • Save sebzur/47f154c315973d4707ce8703adfb354c to your computer and use it in GitHub Desktop.
Save sebzur/47f154c315973d4707ce8703adfb354c to your computer and use it in GitHub Desktop.
Extracts date of birth from polish PESEL identifier
# -*- 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