Jump to content


Photo

How to query birthdays ...


  • Please log in to reply
8 replies to this topic

#1 vhkristof

vhkristof
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationAchel, Limburg, Belgium

Posted 27 March 2003 - 09:23 PM

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!

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 27 March 2003 - 10:37 PM

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!!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 vhkristof

vhkristof
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationAchel, Limburg, Belgium

Posted 28 March 2003 - 09:13 AM

but the year is 1982, 1983, ...

#4 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 March 2003 - 11:44 AM

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.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#5 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 March 2003 - 11:45 AM

Again - as in another topic... check the date() function in php...

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#6 vhkristof

vhkristof
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationAchel, Limburg, Belgium

Posted 28 March 2003 - 12:48 PM

Concerning the change of year (2003-2004),
would it work completely if I queried a UNIX timestamp?

thx for the replys, really appreciate it!

#7 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 28 March 2003 - 04:38 PM

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!!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#8 vhkristof

vhkristof
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationAchel, Limburg, Belgium

Posted 28 March 2003 - 08:19 PM

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

#9 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 28 March 2003 - 08:57 PM

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!!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users