mySQL question about age

thenewprogrammer

New Member
Messages
45
Reaction score
0
Points
0
I have a registration for age where they have to choose month, choose day, and type in the year. i got 1 field for age. Question 1: can i store all values into that field like day, month, year? Question 2: if i wanted to echo out the birthday of the person and than age above it can i pull out the year only in the age field of their birthday. so i can subtract 2009 by their birthday year for their age? or is their better way to do this
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Unsure what you're looking for in question 2, but the answer to question 1 is Yes.

Use the field-type "Date" and it'll let you store the day, month, and year. Should you later need something that lets you store a time as well, use DateTime - lets you store the time AND the date in one field :)


I imagine PHP has functions for determining a timespan between two dates as well, although I dunno them off the top of my head. But the timespan between BirthDate and Today would be their age, so that might be something to look into more :)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
2) PHP Date/Time functions and DateTime class. Unfortunately, many methods of DateTime require PHP 5.3.0, which isn't yet used on the X10 servers. For now, you'll probably have to roll your own using (e.g.) getdate and maybe strptime or strtotime, depending on how you store the date (as Date or integer timestamp). The most maintainable solution would be to extend DateTime, testing for and implementing the methods missing in < 5.3.0. The test (using get_class_methods) is so the script runs under older & newer versions of PHP.
 

nirajkum

New Member
Messages
159
Reaction score
0
Points
0
thanks for the script .. Actually I had the same problem with calculating time difference
 
Top