Jump to content

Don't show if out of date..


adamjblakey

Recommended Posts

Hi,

 

What i am trying to do is when i am running an sql query i don't want to show an entry if the available date is already come and gone. In the table the available date is stored like e.g. 30-05-2007 so if this date is not below the current date +24hours then it does not show.

 

I hope this makes sense.

 

What i was trying to do is :

 

$currentdate = date("d-m-Y")+172800;

$selects = "SELECT * FROM vehicles WHERE available < '$currentdate' ORDER BY 'available'";

 

But it does not work

 

Any ideas?

Cheers,

Adam

Link to comment
Share on other sites

It might because you look like you are storing the date in a varchar field, so MySQL will be treating the date field as a string, rather than a date. You'll have to change that. It should be in the format of Y-m-d, unless you changed it in the mysql ini, which I doubt.

Link to comment
Share on other sites

It might because you look like you are storing the date in a varchar field, so MySQL will be treating the date field as a string, rather than a date. You'll have to change that. It should be in the format of Y-m-d, unless you changed it in the mysql ini, which I doubt.

 

He needs to store it as an INT(11) for a UNIX Timestamp or the date field to use MySQL for date calculations. Varchar is taken literally so running operators on it does no good.

Link to comment
Share on other sites

Right what i have done is change the field to a date inplace of varchar now all the dates in the table are setup like e.g. 2007-05-30 then i tried changing the statement to

 

$currentdate = date("Y-m-d", mktime(0, 0, 0, date('m'), date("d") + 1, date("Y")));
$selects = "SELECT * FROM vehicles WHERE available < '$currentdate' ORDER BY 'available'";

 

But this does not work.. What am i doing wrong here?

 

Cheers,

Adam

Link to comment
Share on other sites

Right what i have done is change the field to a date inplace of varchar now all the dates in the table are setup like e.g. 2007-05-30 then i tried changing the statement to

 

$currentdate = date("Y-m-d", mktime(0, 0, 0, date('m'), date("d") + 1, date("Y")));
$selects = "SELECT * FROM vehicles WHERE available < '$currentdate' ORDER BY 'available'";

 

But this does not work.. What am i doing wrong here?

 

Cheers,

Adam

 

Remove the single quotes from available and $currentdate in the SQL.

Link to comment
Share on other sites

Thank you again but i still cannot get this to work. When this is what i have now but it shows no results even though i have an entry which is 2007-08-09 and even this does not show.

 

The current code is:

 

$currentdate = date("Y-m-d", mktime(0, 0, 0, date('m'), date("d") + 1, date("Y")));
$selects = "SELECT * FROM vehicles WHERE available < $currentdate";

 

Any ideas?

Link to comment
Share on other sites

$currentdate = date("Y-m-d", (time()+3600*24));
$selects = "SELECT * FROM vehicles WHERE available < $currentdate";

 

Try that. the 3600 = 1 hour in seconds, times it by 24 to simulate tommorow. Time returns a unix timestamp.

Link to comment
Share on other sites

Right i need to scrap this as its not working and then go back to the drawing board.

 

At the moment the date is coming from the user as e.g. 2007-07-12 from a JavaScript popup calender then passed to the database in this format.

 

If the date is more than 1 day older than the current date then it does not show.

 

This is the code i have at present but does not work and simply does not show any items.

 

$currentdate = date("Y-m-d", (time()+3600*24));
$selects = "SELECT * FROM vehicles WHERE available < $currentdate";

 

Does anyone have any ideas on why this is not working or any ideas what i can do differently to get this to work?

 

Cheers,

Adam

 

 

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.