The problem is that I want to list the orders that haven´t been payed at the end of the selected month (for example october 31.10.2015)
That means:
list all orders from the beginning of time to 31.10
AND date_payed BETWEEN (1.11 - today)
AND date payed = NULL or before 1970
$sel_date = 10-2015 (the selected day)
$s3 = 11-2015 //in this case
from
octt_order
WHERE order_status_id >= 1
AND (date_format(date_added,'%m-%Y') BETWEEN '11-2010' AND '$sel_date')
AND (date_payed BETWEEN STR_TO_DATE('$s3','%m-%Y') AND STR_TO_DATE('11-2300','%m-%Y') OR date_payed is NULL)
ORDER BY date_format(date_added,'%Y/%m/%d') ASC");
This was the solution for me
octt_order
WHERE order_status_id >= 1
AND (date_added BETWEEN STR_TO_DATE('01-2001','%m-%Y') AND STR_TO_DATE('$s3','%m-%Y'))
AND (date_payed BETWEEN STR_TO_DATE('$s3','%m-%Y') AND STR_TO_DATE('11-2300','%m-%Y') OR date_payed is NULL)
ORDER BY date_format(date_added,'%Y/%m/%d') ASC");