Reputation: 336
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';
}
Upvotes: 1
Views: 713
Reputation: 54796
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';
}
Upvotes: 4
Reputation:
Use the php Date and Time class
Something like this:
$today=new DateTime("2017-07-27");
$other_day=new DateTime("2017-07-28");
$check = $today->diff($other_day);
$difference = (integer)$check->format( "%R%a" );
echo $difference;
Upvotes: 3