samona Posted June 11, 2008 Share Posted June 11, 2008 Hi, I'm trying to create a query that will look back to a previous entry and retrieve the information on that record. I figured out how to do it when its Friday. if (date('D') == "Mon") { $query = 'SELECT * FROM Table WHERE ((DATE_FORMAT(Table.Current_Date, \'%Y %m %d\')) = (DATE_FORMAT(NOW() - INTERVAL 3 DAY, \'%Y %m %d\'))) && (Type = \'type\')'; } else { $query = 'SELECT * FROM Table WHERE ((DATE_FORMAT(Table.Current_Date, \'%Y %m %d\')) = (DATE_FORMAT(NOW() - INTERVAL 1 DAY, \'%Y %m %d\'))) && (Type = \'type\')'; } However, if there is a holiday, the -3 days will not work since the last record could have been inserted 4 days ago or even 5 days ago. How would I solve this problem? Quote Link to comment Share on other sites More sharing options...
fenway Posted June 12, 2008 Share Posted June 12, 2008 Well, this "problem" is simply that you need to know what dates are holidays... do you have such a table? As an aside, your code will be much easier to read (and write) if you have your $query variabled double-quoted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.