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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best format for a date time?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
0
0
GB
Hi,

I'm trying to setup a perl script that will grab results that are older (or newer) than the current time.

Code:
SELECT * FROM Links WHERE expiredate2 < '2012-01-10 02:04:39'

This gives a syntax error, but weirdly - using > doesn't seem to:

Code:
SELECT * FROM glinks_Links WHERE expiredate2 > '2012-01-10 02:04:39'

The value stored in the table needs to be in the yyyy-mm-dd hh:mm:ss format, but I'm not sure why the < isn't working right?

TIA

Andy
 
Hi

Your query works for me in MySQL 5.1.41 in its [tt]mysql[/tt] command-line tool.

By the way, for "older (or newer) than the current time" why not compare to [tt]current_timestamp[/tt] ( or [tt]now()[/tt] ) ? Well, supposing expiredate2 is of type [tt]timestamp[/tt].

Feherke.
 
Hi,

Thanks for the reply. Eugh, it was me being stupid! The query I posted was just a simplified one of the query I was actually using. It turned out I also had isNew => Yes in the query, which wouldn't match anything ;)

Thanks for the reply though!

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top