473,413 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Calculating age in mysql

26
I have a table called 'Animals' in a mysql database.
The columns / fields are:
'name'
'animal'
'year born'

The 'year born' field / column only contains a year such as 2000

I need help for these 2 items:
1) I am trying to calculate the animals age.

2) for a different query I am trying to calculate the animals age in human years, which is by multiplying the animals age by 3


Thanks for your help
Jul 11 '10 #1
4 2862
TheServant
1,168 Expert 1GB
Why are you trying to do this all in the database? MySQL is mainly for storing data which can be called with other languages and used.

If you are using PHP, you can simply call that year and then subtract it from this year.

Why don't you have a date column instead of your year column, which I presume is just an INT?

If you change that to DATE (so you have day and month as well as year) then you can use some of MySQL date functions.
Jul 11 '10 #2
ozchadl
26
I would prefer not to alter the field / column name and any data.
I know that it is possible to do this age calculation in mysql.
Jul 11 '10 #3
TheServant
1,168 Expert 1GB
I still don't understand what you want? Do you want a MySQL output on ages?

Expand|Select|Wrap|Line Numbers
  1. SELECT (YEAR(CURRENT_DATE)-yearBorn) WHERE ...
Jul 12 '10 #4
ozchadl
26
I got it to finally work
This is part of the code that I used, which works to calculate the age

left(curdate(),4) - (year born)
Jul 12 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
3
by: Fadzi Ushewokunze | last post by:
hie there.. just wondering how much would one charge a company that wants a solution that will include jsp/servlets/mysql and a few ejbs or just normal beans. this might take me 8-10wks to...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
by: The Bit Bandit | last post by:
Hopefully someone can help me create a query that I'm having some trouble with. I have three tables: invoices, invoicedetails, invoicepayments The fields are: invoices -------- InvoiceNo
1
by: izmanhaidi | last post by:
Hi, For my final project,I must do cafeteria systems with mysql backend database. This is my system. Student will have $10 and will deduct for breakfast,lunch and dinner.If they eat...
57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
6
by: bill | last post by:
I am about to start on a module that will accept a location from a user, use Google geolocation services to get the lat/lon and then compute the distance from the site visitor to about 100 kennels...
2
jkmyoung
by: jkmyoung | last post by:
Calculating Large Exponents Background: This is a quick article as to how to calculate the exponents of large numbers quickly and efficiently. Starting with a basic multiplication algorithm, it...
1
by: liam kitson | last post by:
Hello, I have a mysql database called sensor_data. Every 30 minutes a script inserts the power usage to this database and also the cost depending on the day/night tariff Rec Date Time ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.