Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data representation and storage - person's age

I have a design issue I'm facing, I bring it up here so maybe I can get more ideas.

Currently in my project, I have a scenario where I need to represent the age of children.

The age can be from 0 to 15. from age 1 to 15 it's easy, I can store it as an integer, but the problem is if the age is between 0 and 1. Then I want to store it in months.

Storing the age as a java.util.Date won't work because I don't want to do comparison with the current date (I'm dealing with a really big database). regarding floating point, well you know that there are 12 months in one year, so then I need to to translate 0.5 to six months and 0.7 to I don't know...

I'm looking for a good way to store the age in one type. It can be Enum, etc. It should be small as possible. and it should be possible to persist the type in a database without any issues...

like image 555
stdcall Avatar asked Dec 05 '22 19:12

stdcall


1 Answers

You could always store the age in an appropriate small unit (e.g. months), and convert it to years when you want.

like image 67
Basile Starynkevitch Avatar answered Dec 15 '22 01:12

Basile Starynkevitch