dragon_sa Posted January 11, 2011 Share Posted January 11, 2011 I need to run a mysql query to check if an input date variable formatted to yyyy-mm-dd is not between a startDATE and finishDATE which are columns in a table, some of which have the value NULL. NULL values can be returned but dates equal to or between the 2 column dates cannot. Basically startDATE and finishDATE are column headings for staff holiday dates, and a user query is checking for all staff not on holiday on the input date, effectively listing the available staff on the input date. The NULL value in those columns mean a staff member has not booked any holidays. Any help much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/224065-check-date-variable-not-between-2-dates-in-database/ Share on other sites More sharing options...
jdavidbakr Posted January 11, 2011 Share Posted January 11, 2011 Are your column types "DATE" or "DATETIME"? If so, it's trivial select * from table where date < '{$startDATE}' or date > '{$finishDATE}'; Quote Link to comment https://forums.phpfreaks.com/topic/224065-check-date-variable-not-between-2-dates-in-database/#findComment-1157952 Share on other sites More sharing options...
Pikachu2000 Posted January 11, 2011 Share Posted January 11, 2011 Or: SELECT * FROM `table` WHERE `date` NOT BETWEEN '$startdate' AND '$enddate' Quote Link to comment https://forums.phpfreaks.com/topic/224065-check-date-variable-not-between-2-dates-in-database/#findComment-1157989 Share on other sites More sharing options...
dragon_sa Posted January 11, 2011 Author Share Posted January 11, 2011 they are date fields, and the date to check is a variable from an input form selected from a calandar, startDATE and finishDATE are the columns in the table and some could = NULL Quote Link to comment https://forums.phpfreaks.com/topic/224065-check-date-variable-not-between-2-dates-in-database/#findComment-1158029 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.