Jump to content

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

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.