Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date comparison 1

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
Hello,

what I want is to check if the date coimg from mysql is equal to or less than the current date.

here is my code



<?
$tmp=time();
$date=date(&quot;Y-m-d&quot;,$tmp);

$sql=&quot;SELECT * FROM table_name WHERE issuedate <= '$date' ORDER BY issuedate DESC LIMIT 1&quot;;

?>

so that the latest article will be displayed .

The issuedate column is of type date ie YYYY-mm-dd
so if the issuedates in the table are say
2002-08-30 and 2002-08-23,till 29th aug article of issudate 23rd aug and on 30th aug the article of issuedate 2002-08-30 shd get displayed
I am having a problem with the date comparison with the above query..

what is the mistake i have made there ?

Thanks in advance

spookie



[/color] --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Try this in mysql :)
SELECT @today:=curdate(),@mydate:=YOUR_DATE_FIELD,if(@mydate <= @today,&quot;equal or less&quot;,&quot;not equal or less&quot;); ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
That works karver..

but the result i could have acheived in a single query, i have to write ifs and whiles unnecessarily.

i dont understand why the comparison not worked in mysql because that will make the job much easier..

thanks

spookie --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
$sql=&quot;SELECT * FROM table_name WHERE issuedate <= curdate() ORDER BY issuedate DESC LIMIT 1&quot;;

//relies on issuedate being in yyyy-mm-dd format.

Always play with things and see what you can make from them :)

I wasn't sure if you wanted to return a statement for the value comparison or results dependant on the date. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
sorry,

my fault!!

this forum can make u lazy sometimes :)

The code i was having trouble with works fine (cache problem i think)

anyways thanks karver.

spookie --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top