Verbose Logging

software development with some really amazing hair

17 Jun 09

08:00 AM MDT

Posted in Programming

Calculating age

I found this little snippet on stackoverflow

This is a strange way to do it, but if you format the date to yyyymmdd and subtract the date of birth from the current date then drop the last 4 digits you’ve got the age :)

I don’t know c#, but i believe this will work in any language.

20080814 – 19800703 = 280111

drop the last 4 digits = 28

All credit goes to ScArcher2

This is just a great little snippet of code, and as an upside, dates in that format are easily sortable by standard numerical sorting methods (read: fast).

Original question and answer

Share/Bookmark

blog comments powered by Disqus