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
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
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.