-1

I am trying to calculate someones age based off of birthday, birthMonth and birthYear. I would like to create an age column and calculate their age based off the 3 other columns stated above.

Thank you

Kyle
  • 29
  • 6

1 Answers1

0

Thank you everyone. I am using Navicat. I ended up going with the below query which worked

ALTER TABLE "12441_load2_all" ADD COLUMN cm_age int8;

update "12441_load2_all" set cm_age = date_part('year',age(("BirthYear"||'-'||"BirthMonth"||'-'||"BirthDay")::date)) where is_date(("BirthYear"||'-'||"BirthMonth"||'-'||"BirthDay"));

Kyle
  • 29
  • 6
  • It seems like a bad idea to store the age like this. You will need to update it either every day or every time you query the table, plus every time you insert a new record and every time you correct a birthdate in the other columns. A view or something seems much safer (unless you only want the age at the time the record was created). – EdmCoff Aug 05 '22 at 19:35
  • I only needed the age for a project that lasts 3 days and no future records are being added to the table. I didn't need it for a long period of time, but your suggestions are valuable and I appreciate it. – Kyle Aug 05 '22 at 21:55