Jump to content

Expiry date


Teaky

Recommended Posts

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…

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

SELECT link FROM table WHERE exp_date <= $today[/code]

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

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

Teaky
Link to comment
https://forums.phpfreaks.com/topic/16881-expiry-date/
Share on other sites

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.

so

$qry = "SELECT link FROM table WHERE exp_date >= NOW()";
$qry = mysql_query($qry);
Link to comment
https://forums.phpfreaks.com/topic/16881-expiry-date/#findComment-71077
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.