Jump to content

Archived

This topic is now archived and is closed to further replies.

vhkristof

How to query birthdays ...

Recommended Posts

Hey,

 

Here is what I want to do ...

I\'ve got a table with the birthdays (when they were born, year eg 1982).

I wan\'t to select the people who will celebrate their birthday

between tomorrow and 8 days from now ...

 

Is there a way?

Problem is the years are 1982, 1983, ... and not 2003

 

Thx!

Share this post


Link to post
Share on other sites

All u have to do is get the date difference

 

I guess we have discussed about that in one of the postings

 

 

$sql = \"select TO_DAYS(\'$today\')- TO_DAYS(\'$birth_date\')\";

 

and u have to collect all the value which has difference < 8

 

Hope I am clear!!

Share this post


Link to post
Share on other sites

So what ? You should just extract the day and month (probably getting dayofyear is best)...

 

then

 

if ($birthday_dayofyear-$today_dayofyear < 8) {

...

}

 

I\'m not sure what will happen around december 24th and forward....

 

P.

Share this post


Link to post
Share on other sites

Concerning the change of year (2003-2004),

would it work completely if I queried a UNIX timestamp?

 

thx for the replys, really appreciate it!

Share this post


Link to post
Share on other sites

Ok

 

Now say his b.day is on

 

1982 - 1 - 30

yyyy-mm-dd

 

Now instead o 1982 add the current year

 

if u add 1982 u will get the total date like \"7192\" which is not needed

 

Just subtitue with current year

 

select TO_DAYS(\'2003-1-24\') - TO_DAYS(\'2003-1-30\')

 

This will give \"-6\" so 6 days left for his b.day if u get a +ve value that means his b.day is over.

 

Hoep I am clear!!

Share this post


Link to post
Share on other sites

but when the birthday is on 1 january and i query the db

on 31 december ?

Share this post


Link to post
Share on other sites

Good question

 

Now u should write a bit of coding to check this stuff

 

Now in this case the current month is 12 and we are looking for future b.days so we have to change the year here

 

so if u see the month as \"1\" and the current month as \"12\"

 

increment the year eg 2003 + 1 = 2004

 

if the bithday month is less than the current month increment the year

 

Hope this helps!!

Share this post


Link to post
Share on other sites

×

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.