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!

datediff substitute in mysql 3.23.58

Status
Not open for further replies.
Aug 23, 2004
174
US
I'm looking for a way to subtract and event date from the current date in order to find upcoming events.

This is a piece of the old working code.

Code:
$SQL = 'SELECT * 
	FROM events e
	WHERE DATEDIFF("'.$today.'",e.E_End_Date) <= 1 ';
 
note you do not need to feed in to mysql the value of the current date, mysql knows what the current date is :)

... WHERE TO_DAYS(e.E_End_DATE) - TO_DAYS(CURRENT_DATE) <= 1

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
mysql knows what the current date is

True, but if you have a separate web server and database server, you should read the dates from one server only or face some funny and inexplicable results when one of those servers has its clock out of tune. So if you save dates from PHP, it is actually good to compare them with dates from PHP.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top