Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL needs AGE function.

 
Goto page Previous  1, 2
   Database Forums (Home) -> PHP SQL RSS
Next:  how can i put multiple statmwnts in sum(case...  
Author Message
NC

External


Since: Apr 16, 2007
Posts: 40



(Msg. 16) Posted: Sun Jan 06, 2008 7:10 pm
Post subject: Re: SQL needs AGE function. [Login to view extended thread Info.]
Archived from groups: alt>comp>lang>borland-delphi, others (more info?)

On Jan 6, 12:38 am, "Skybuck Flying" wrote:
>
> I want to select people from a database within a certain
> age range.

So what's the problem? Compute the range of birth dates on the client
side and stick them into your query...

> For example:
>
> Select * From TablePerson Where (Age(Birthdate) > 20) and
> (Age(Birthdate) < 9Cool
>
> That would make it really easy.

What's wrong with this (in PHP):

$low = date('Y-m-d', strtotime('98 years ago'));
$high = date('Y-m-d', strtotime('20 years ago'))
$query = "SELECT * FROM `TablePerson` WHERE " .
"`Birthdate` > '{$low}' AND `Birthdate` < '{$high}'";
$result = mysql_query($query);

I really don't see what the problem is...

Cheers,
NC

 >> Stay informed about: SQL needs AGE function. 
Back to top
Login to vote
David Kerber

External


Since: May 11, 2006
Posts: 34



(Msg. 17) Posted: Mon Jan 07, 2008 9:26 am
Post subject: Re: SQL needs AGE function. [Login to view extended thread Info.]
Archived from groups: alt>comp>lang>borland-delphi, others (more info?)

In article ,
says...
> Ok, this weblogger guy writes:
>
> "
> Date values in SQL is always saved in "MM/DD/YY(YY)" format.

He's wrong. It may be true for some SQL engines, but not all.

> Here's a line of code to get the string in the correct format for SQL:
> FormatDateTime('mm"/"dd"/"yyyy', Now)

Only good for Access. Most client-server engines want either yyyymmdd
or yyyy-mm-dd (some will take either).

> "
>
> So I tried:
>
> where (Birthday > 01/01/1970)
>
> Seems to be working so far.
>
> So far so good.
>
> Soon I'll post some nice code, for age range selecting Wink
>
> Bye,
> Skybuck.
>
>
>

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).

 >> Stay informed about: SQL needs AGE function. 
Back to top
Login to vote
Paul Lautman

External


Since: Feb 28, 2006
Posts: 55



(Msg. 18) Posted: Mon Jan 07, 2008 3:59 pm
Post subject: Re: SQL needs AGE function. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Skybuck Flying wrote:
> Ok, this weblogger guy writes:
>
> "
> Date values in SQL is always saved in "MM/DD/YY(YY)" format.

He is talking out of his arse.

Date values are stored in database tables in whatever internal format the
designers choose. It may well be in UNIX datetime format, but it is likely
to be anything.

Rather than looking at what weblogger guys write, why not use the manual for
whatever product you are using.

Oh that's right, you don't want to use the manual for something as "simple"
as dates, you want to spend hours getting it wrong. Silly me, I forgot!
 >> Stay informed about: SQL needs AGE function. 
Back to top
Login to vote
MikeB

External


Since: Mar 12, 2007
Posts: 2



(Msg. 19) Posted: Mon Jan 07, 2008 3:59 pm
Post subject: Re: SQL needs AGE function. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Paul Lautman" wrote in message

> Skybuck Flying wrote:
>> Ok, this weblogger guy writes:
>>
>> "
>> Date values in SQL is always saved in "MM/DD/YY(YY)" format.
>
> He is talking out of his arse.
>
> Date values are stored in database tables in whatever internal format the
> designers choose. It may well be in UNIX datetime format, but it is likely to
> be anything.

Precisely.. The internal format is going to be whatever the designer made.
Presentation format is determined at runtime (for coding) and in Display Format
(for reporting), all chosen based on the requirements of the presenter..

> Rather than looking at what weblogger guys write, why not use the manual for
> whatever product you are using.
>
> Oh that's right, you don't want to use the manual for something as "simple"
> as dates, you want to spend hours getting it wrong. Silly me, I forgot!
>
 >> Stay informed about: SQL needs AGE function. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
copy function Q - Can anyone tell me why this isn't working.. I am sure its just something stupid but I can't see it yet. <?PHP function uploadpic($pic){ foreach($pic as $value){ copy ($_FILES['$value']['tmp_name'], $_FILES['$value']['name']) or die...

Simple php MySQL function - Hello I looking for a php /SQL function that should show the next or previous record from a SQL table. At the bottom of the window I will put two buttons with the following picture < >. This function should respect the alphabetic order from on...

PASSWORD function in MySQL - How big should a password field be in a table when using the MySQL PASSWORD function? Can I calculate how big the hashed value will be (in terms of number of characters) if I limit the user to say 16 character passwords? Thanks, Rick..

Newbie needs help with mail function - Hi, I've got so far with the mail() function but it won't work. Please help. WHere am I going wrong? Kind regards, Raj (Newbie) $to="def@ghi.com"; $email_system="abc@def.com"; $message="Hi"; $headers = "From: &quo...

Mail function sends to gmail but not hotmail. Please help .. - Hi, Can anyone tell me what the requirements are to allow hotmail to collect messages. I have a script using the mail function at the moment that emails most email clients but the email doesn't seem to be accepted by hotmail. It email doesn;t even go...
   Database Forums (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Goto page Previous  1, 2
Page 2 of 2

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]