Finnish social security number is datemask ddmmYYxAAbc
- dd = date with two numbers.
- mm = month with two numbers.
- YY = year with two numbers.
- x = "delimeter" character. It can be '+','-' or 'A'. It presents century.
- '+' = 1800
- '-' = 1900
- 'A' = 2000
- AAbc = varying numbers and caharacters for id purposes including cheksum. We are not interested in about it this time.
SQL-query:
DECLARE @sSecurityId char(11);
SET @sSecurityId = N'221177-123Z';
select CONVERT(date, CASE SUBSTRING(@sSecurityId, 7, 1)
WHEN '-' THEN '19'
WHEN 'A' THEN '20'
WHEN '+' THEN '18'
END + SUBSTRING(@sSecurityId, 5, 2) + SUBSTRING(@sSecurityId, 3, 2) + SUBSTRING(@sSecurityId, 1, 2)) as birthdate
Result: 1977-22-11
Keywords for Finnish developers:
Kuinka muuttaa suomalainen sosiaaliturvatunnus, eli sotu, päivämääräksi tai päiväksi SQL-haun avulla.