+ Reply to Thread
Results 1 to 5 of 5

Thread: mySQL question about age

  1. #1
    thenewprogrammer is offline x10Hosting Member thenewprogrammer is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    45

    mySQL question about age

    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

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: mySQL question about age

    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


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: mySQL question about age

    here is a script to tell time ago.

    http://www.sajithmr.com/php-time-ago-calculation/

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: mySQL question about age

    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.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    nirajkum is offline x10 Sophmore nirajkum is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    161

    Re: mySQL question about age

    thanks for the script .. Actually I had the same problem with calculating time difference

+ Reply to Thread

Similar Threads

  1. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  2. Problemas para conectar con MySQL
    By rquesada2710 in forum Soporte
    Replies: 2
    Last Post: 09-01-2008, 09:17 PM
  3. PHP MySQL Question..
    By anuj_web in forum Programming Help
    Replies: 7
    Last Post: 04-26-2008, 05:43 AM
  4. 2 questions about MySQL
    By chrisosx in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 07-06-2005, 03:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers