Calculated fields in a database

manchicken manchicken at notsosoft.net
Tue Jun 26 15:51:57 UTC 2007


On Tuesday 26 June 2007 08:41:24 Neil Winchurst wrote:
> I am learning knoda and hk-classes as a good way of setting up a
> databases on Linux. I have used Linux for six years now and I have been
> involved with databases for over 15 years. This knoda/mysql setup is
> the best I have found so far in Linux.
>
> I don't know about other people, but I find the help files rather
> difficult to follow sometimes. For example there is no page explaining
> how to set up a sub-form. I am still playing with that.
>
> Calculated fields. Let me give an example of what I mean. You have a
> list of people including date of birth. You need to have their age
> showing on the form. Obviously this will change with time. So you need
> a calculated field which takes the current date and subtracts the date
> of birth to calculate the age. Since this is a calculated field it will
> always be up to date and accurate.
>
> The important thing about this 'age' field is that **it is not part of
> any table. It appears on the form only.** There are other examples such
> as a sales form which has a field to calculate the cost for each item
> (price times quantity), and another field to show the total charge for
> all the items. Again, these two fields will not appear in any table,
> only on the form.
>
> Is there any way in knoda/hk-classes to do this sort of thing? It is a
> facility which I used again and again when I was writing databases in
> Windows (using Borland Paradox).
>
> Thanks for any help and/or information
>
> Neil Winchurst

You could always just stick it into your query.  I don't know how to do this 
in MySQL, butyou could just turn the two dates to epoch, subtract today from 
the birthdate, and then divide it by (60*60*24*365.25) to get the years.

-- 
~ manchicken <><
(A)bort, (R)etry, (I)nfluence with large hammer.
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html




More information about the kubuntu-users mailing list