Deepak Agrawal Deepak Agrawal - 1 year ago 76
PHP Question

How to get birthday date in form of today, tomorrow, yesterday?

I want to get birthday dates in form of 'Today' ,'Tomorrow','Yesterday' form.


  • 1.if candidate birthday was on 26-july-1991 it should be print 'yesterday'

  • 2.if candidate birthday is on 27-july-1991 it should be print 'today'.

  • 3.if candidate birthday will on 28-july-1991 it should be print 'tomorrow'.



code

$current = strtotime(date("Y-m-d"));
$date = strtotime("2014-07-24");

$datediff = $date - $current;
$difference = floor($datediff/(60*60*24*365));
if($difference==0)
{
echo 'today';
}
else if($difference > 1)
{
echo 'Future Date';
}
else if($difference > 0)
{
echo 'tomarrow';
}
else if($difference < -1)
{
echo 'Long Back';
}
else
{
echo 'yesterday';
}

Answer Source

Maybe a bit complicated solution, but here I compare month num and date num:

$current_month = date("n");
$current_day = date("j");

// date of birth
$dob = strtotime("1991-07-26");
$dob_month = date("n", $dob);
$dob_day = date("j", $dob);

if ($current_month == $dob_month) {
    if ($current_day == $dob_day) {
        echo 'TODAY';
    } elseif ($current_day == $dob_day + 1) {
        echo 'YESTERDAY';
    } elseif($current_day == $dob_day - 1) {
        echo 'TOMORROW';
    } else {
        echo 'IN this month';
    }
} elseif ($current_month < $dob_month) {
    echo 'In future';
} else {
    echo 'Long back';
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download