Jump to content

[SOLVED] Date Question


brissy_matty

Recommended Posts

Hi All,

 

Getting stuck on a bit of a date problem. I want to display "ACTIVE" if the startdate is the current date or greater then the current date BUT less then or equal to the enddate. Basically to show if an item is active or not within a current date range. $startdate & $enddate both come from a date column in a mysql database.

 

Below is what i thought would have worked... Apparently not.. Any ideas appreciated

 

 

<?php
$startdate=mysql_result($result,$i,"startdate");
$enddate=mysql_result($result,$i,"enddate");
$current=date("Y-m-d");
if ($current <= "$startdate" && $current >= "$enddate")
{
$status="<font color='green' face='verdana' size='1'>ACTIVE</font>";
}
else
{
$status="<font color='red' face='verdana' size='1'>INACTIVE</font>";
}
?>

 

Thanks Heaps

Matt

Link to comment
https://forums.phpfreaks.com/topic/62939-solved-date-question/
Share on other sites

you COULD simply use MySQL to its advantage here and add it as part of your SELECT query:

 

SELECT stuff, (CASE NOW() WHEN BETWEEN startdate AND enddate THEN 'ACTIVE' ELSE 'INACTIVE' END) AS status FROM table

 

have a look in the MySQL manual at the functions and operators section, you'll find a plethora of handy things.

Link to comment
https://forums.phpfreaks.com/topic/62939-solved-date-question/#findComment-313385
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.