Jump to content


Expiry date

  • Please log in to reply
1 reply to this topic

#1 Teaky

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 August 2006 - 10:39 AM

Hello there, :D

I have a job, which asks me to display links on a web page, as long as their expiry date is valid. Basically I need a piece of code that…

1) Grabs the Expiry date from the column of the table.
2) It then compares it to today’s date.
3) Only display the link if it hasn’t reached its expiry date.

The way I did it was…

$today = date("d/m/y");

SELECT link FROM table WHERE exp_date <= $today

However this only compares the first values i.e. the days and it ignores everything else. :(

I’ll be grateful for anyone who helps.  :)


#2 ToonMariner

  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 11:07 AM

Where possible it is better NOT to use php's date/time functions - those in mysql are far superior.

if your database table has a field with the data type of date or datetime (or similar) it would simply be a case of using NOW() in the query.


$qry = "SELECT link FROM table WHERE exp_date >= NOW()";
$qry = mysql_query($qry);
follow me on twitter @PHPsycho

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users