Jump to content

DOB problems


wilna

Recommended Posts

Hi, I hope someone can help me.  I am trying to generate a script for our Intranet that tells me which birthdays = today.  My field in my table = d/m/y, eg 09/05/2011 (9 May 2011).  How do I get the script to just look at the day & month, not the year?  My script looks like this:

 

<?php

echo date("d/m/Y") . "<br />";
$myDate = date('d/m/Y');
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);

$sql = "SELECT * FROM detail WHERE dob='$mydate'";
$result=mysql_query($sql);
echo mysql_num_rows($result);

?>

Link to comment
Share on other sites

what is the data type for your dob field? If you used a date type then you can just do it all in one query

SELECT * FROM detail WHERE dob = CURDATE()

 

and if you use a datetime datatype:

SELECT * FROM detail WHERE DATE(dob) = CURDATE()

 

and if you wanted to get everyone who had a birthday tomorrow:

SELECT * FROM detail WHERE DATE(dob) = DATE_ADD(CURDATE(), INTERVAL 1 DAY);

 

etc.....................

Link to comment
Share on other sites

thanks, the $myDate = date('d/m'); part works then I get today's date without the year, but my dob field in my table also have a year in so what must I do to get that fields value without the year?

 

My dob field is just a date type field, does that 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.