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
https://forums.phpfreaks.com/topic/115678-solved-if-date-today/#findComment-594705
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
https://forums.phpfreaks.com/topic/115678-solved-if-date-today/#findComment-594715
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.