Jump to content

How come this query returns ages that are 19 and 20 and not 20?


kevinkhan

Recommended Posts

SELECT  ROUND( DATEDIFF( NOW( ) , STR_TO_DATE( bday, '%M %d,%Y' ) ) / 365 ) AS age FROM profile_list WHERE TRUE AND ROUND( DATEDIFF( NOW( ) , STR_TO_DATE( bday, '%M %d,%Y' ) ) / 365 ) = 20

 

 

i know this isnt the best format but the date of births are stored like this

 

April 10, 1991

May 6, 1991

 

How come the query returns ages that are 19 and 20 and not just 20 like what i want?

 

i only want the dates to be return which are between todays date which is the 1/20/2011 and 1/20/2012

Link to comment
Share on other sites

ok i think i need to change my bday comumn in my database into the correct format and use date datatype

 

is there a way of converting all the existing dates which are `bday` text CHARACTER SET latin1 NOT NULL, into a date datatype

and anywhere the existing format is like "February 4" and the year is not included have it insert like 0000-02-04 otherwise if the date is like August 22, 1985 have it formated like 1985-08-22

 

Thanks for your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.