Aleksandar Ilijevski Aleksandar Ilijevski - 19 days ago 5
SQL Question

Automatically update people's ages in sqlite

How do I automatically update people's age in an SQLite database? I have put their "DateOfBirth" column, and I created another column called "Today" which is supposed to display the current date by putting
"Set Today = date('now')" function.
Then I made created the Age column which calculates their age by subtracting their birth dates from the current date (Today-Date of birth), which seems to do the job.
But, the problem is that the TODAY isn't automatically updated, what do I do? Thanks everyone in advance, cheers

Answer

How do I automatically update people's age in an SQLite database?

You don't need to since Age is a computed column and thus while displaying the data you can calculate the age and show it accordingly. Since you already have DOB stored you just need to get teh difference from CurrentDay - DOB to get the age.

Use a UPDATE statement to update your Today column

update your_table set Today = date('now')