Jump to content

[SOLVED] if (date == today ) ?


hassank1

Recommended Posts

Guest Xanza

It would depend on the format of $PostDate... For example, if $PostDate shows the date as: "Weekday, Month date" (Example: Monday, April 25) then this would work:

 

<?php

if($PostDate == date("l, F d")){
   echo "Today";
}

if($PostDate == date("l, F d")-1){
   echo "Yesterday";
} 

?>

 

This should work, depending how your initial SQL variable is output, just change date() to suit your needs. Hope this helped!

Link to comment
Share on other sites

I've used your code to implement these functions .. and everything worked just fine :)

 

 

function isToday($date) //check if it's today
{
  $date = date("l, F d",strtotime($date));
  if($date == date("l, F d"))
  return true;
  else
  return false; 
}



function isYesterday($date) //check if it's yesterday
{
  $date = date("l, F d",strtotime($date));
  if($date == date("l, F d")-1)
  return true;
  else
  return false; 
}

 

 

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.