0

I have a table with data for customers. Each entry has a specified customer and a start date and an end date. I want to display specific customer data that has startdate between two variables, i.e. i ask the user on the frontend to choose 1. a customer and 2. startdate to start somewhere between x and y. So that the displayed data doesn't take the end date into account because it's more important to see what data is starting in that time range and not what data is ending.
I used to do this like this:

WHERE c2c.CUSTOMER LIKE '%". $customers ."%' AND (MASTER.MASTER_SCHEDULED_START_DATE >= '". $datumanf . "' AND MASTER.MASTER_SCHEDULED_START_DATE <= '". $datumend . "') 

This looked like it worked! Until I noticed that it only displays data where the start date and the end date are on the same day.

After researching on Stackoverflow I tried MySQL BETWEEN

WHERE c2c.CUSTOMER LIKE '%". $customers ."%' AND (MASTER.MASTER_SCHEDULED_START_DATE BETWEEN '". $datumanf . "' AND '". $datumend . "') 

But this still somehow takes the end date into account, for it shows the exact same results as before: Only those where the startdate and the enddate are on the same day and between that defined range. I don't understand this because I don't use the end date at all in this query.

10
  • 2
    This query is wide open to SQL injections. Commented Feb 4, 2016 at 8:37
  • I know, but I only operate from within a secured virtual network. Please disregard this issue Commented Feb 4, 2016 at 8:38
  • Did you check your data maybe startdate and enddate is always the same for each record? Commented Feb 4, 2016 at 8:40
  • 1
    The firs version should work but you have to define the variables as a date type. There seems to compare strings and i think that is the reason to return only the data that have start and end date on the same day Commented Feb 4, 2016 at 8:41
  • 1
    It works correctly for me: sqlfiddle.com/#!9/c0268/1 Commented Feb 4, 2016 at 8:46

2 Answers 2

1

This might will help you out..

WHERE c2c.CUSTOMER LIKE '%". $customers ."%' AND (MASTER.MASTER_SCHEDULED_START_DATE) BETWEEN ('". $datumanf . "' AND '". $datumend . "') 
Sign up to request clarification or add additional context in comments.

Comments

0

The answer was said first @corinagheorge in the comment section. I had to set datatype first.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.