0
<?php if((date('Y-m-d', strtotime($value->subscription_time)))==(date('Y-m-d'))):?>
<div class="notifications_wrap_inner_text">
    <p>
        <?php echo $value->name;?> wants to join your group.
        <?php echo date('H:i A ',strtotime($value->subscription_time));?>
    </p>
<?php endif; ?>

stackoverflow reference link

Ι want to compare two dates exactly as the above links show compare of greater then and smaller dates and not the exact one the above code runs on each case whether the dates are matching or not matching !!!!
Any suggestions?
Thanks in advance

Community
  • 1
  • 1
saurabh kamble
  • 1,510
  • 2
  • 25
  • 42

2 Answers2

3

your code seems good, but when you try to compare two date string then you should try like this:

<?php if((date('Y-m-d', strtotime($value->subscription_time)))===(date('Y-m-d'))):?>

I hope it will work for you.

Rajen K Bhagat
  • 222
  • 3
  • 9
0

You could do logical operations in both PHP or MySql

I like comparing time using TIMESTAMPS they are much easy to handle (For me)

//format the date to a timestamp format
$subtime = DateTime::createFromFormat('Y-m-d',$subscription_time)->format('U');
//get noe in time stamp format
$now = time();

//add your logical statements here
if($subtime > $now)
{
 // do this
}else{
 // do that
}
tomexsans
  • 4,454
  • 4
  • 33
  • 49
  • it does not support the equal operation only greater or smaller then it does not work – saurabh kamble Jan 03 '14 at 09:58
  • what is your php version? `->format('U')` is not framework specific language, it is native PHP. And your `$subscription_time` must be in Y-m-d Format or Format will not work, if not change,the first param of createFromFormat to the format of your subscription time – tomexsans Jan 03 '14 at 10:03