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
https://forums.phpfreaks.com/topic/235919-dob-problems/
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
https://forums.phpfreaks.com/topic/235919-dob-problems/#findComment-1212760
Share on other sites

Archived

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

×
×
  • 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.