mySQL query help
Code:
$query = "SELECT DATE_SUB(CURDATE(),INTERVAL 3 DAY)"; I want it to return timesheet.checkin where it is older than today -3 days. TIA |
Re: mySQL query help
Quote:
Secondly, you are including $date in the string without quoting it. Depending on the database schema, this may be a bad idea; you should probably use a parameterised query here. It's good practice to always use parameterised queries to include variables in SQL, and if that's not possible for some reason, use DBI::quote to quote the string, rather than just putting quotes around it. Thirdly, this is only a program fragment. You haven't defined mysql_error()or MYSQL_QUERY() anywhere, so we don't actually know the calling semantics of the routines you're using. |
Ok, I double qouted as you said, and I still get the same output. I found a problem in the data types.
SELECT DATE_SUB(CURDATE(),INTERVAL 3 DAY) outputs in the format yyyymmdd without the DATE_SUB it would be yyyy-mm-dd because DATE_SUB seems to change it to a numeric context. where 'lastcheckin' is set by a NOW() function so it is in the format yyyy-mm-dd hh:mm:ss how can I make the two work together? Is there an easy way to modify NOW() and maintain the format for mySQL to compare the dates? I dont really care about the hours for the purpose of the query, it is just looking at absenteeism of more than 2 days +/-. This is probably fairly easy to do, but I'm relatively new to any type of programming. Thanks again, BTW: This is in PHP. |
Quote:
This may be something to do with your date display settings? Quote:
|
All times are GMT -5. The time now is 09:21 PM. |