Jump to content

up coming birthday query


proctk

Recommended Posts

below is what I have this far and it retuns nothing any idea why

[code=php:0]
include '../config/db.php';

$today = strtotime("Now");
$leadDate = strtotime("+350 day", $today);

$get_childdob = mysql_query("SELECT * FROM children WHERE childdob BETWEEN CURDATE() AND '$leaddate'")or die (mysql_error());

while($row_get_childdob = mysql_fetch_assoc($get_childdob)){

$name = $row_get_childdob['childfirstname'];
echo $name;
}
[/code]
Link to comment
Share on other sites

yeah there was a fault in my origonal post

if you are using PHP to obtain the date in the furture you need another line in there
[code]
$today = strtotime("Now");
$leadDate = strtotime("+350 day", $today);

$thisdate = date("Y-m-d", $leadDate);

$get_childdob = mysql_query("SELECT * FROM children WHERE childdob BETWEEN CURDATE() AND '$thisdate'")or die (mysql_error());
[/code]

please accept my apologies, other wise my ammeded post above should work too
Link to comment
Share on other sites

thank you for the update, it gave it a try and its no producing any results. I changed the +150 to 365

I found the below code that gets the values but I don't know how to change it to show birthdays in x days


[code=php:0]
$get_childdob = mysql_query("SELECT owner_id,childdob,IF(
DAYOFYEAR(childdob) < DAYOFYEAR(CURDATE()), DAYOFYEAR(childdob)+366,DAYOFYEAR(childdob)
)as birthdayofyear FROM children ORDER BY birthdayofyear")or die (mysql_error());
[/code]
Link to comment
Share on other sites

I also found this but it return no results

I played around with INTERVAL to make sure there was dates that would result in a positive query

[code=php:0]
$get_childdob = mysql_query("SELECT owner_id, childdob FROM children WHERE childdob Between CURDATE() AND DATE_ADD(CURDATE(),INTERVAL 366 DAY)")or die (mysql_error());
[/code]
Link to comment
Share on other sites

I think I have deterimed part of t he problem.  the date of birth will always be within the date range as it looking at the year of birth, we need to change the year of birth to the current YEAR. i have been googling for hours and connot figure this out
Link to comment
Share on other sites

There has to be a way to take a date from a table and change the year section of the date to the current year and then compare that date to the current year and display it if the date is within 20 days and once the date is past not to display it any more. I have seached google many times and I have not had any luck getting an answer to this question. I'm trying to limit it to one mysql query.


help please
Link to comment
Share on other sites

the other way to do it instead of coverting the year is to go back tomy origonal post and calculte a date that is 20 days in the future
[code]
<?php
$now = strtotime("Now");
$then = strtotime("+350 day", $now);

$today = date("Y-m-d", $now);
$date20 = date("Y-m-d", $then);

$get_childdob = mysql_query("SELECT * FROM children WHERE childdob > '$today' && < '$date20'")or die (mysql_error());

?>
[/code]
sorry for the delay in answering - work gets in the way of everything doesnt it?
Link to comment
Share on other sites

Yeah I saw he has a double post going on after I answered the question.

Only problem with yours is that it will only work on, well children who haven't been born yet :)

A birthdate is going to be stored as '1999-03-18' but you'll want it to match on March 18th of every year.
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.