Advanced Mysql query help

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

DJ-Sound

VIP Member
Impact
32
I need help with a section of my query that handles the "availability checking" aspect of my system. Unfortunately this has to be done in one query, I know how to do it in several with php if statements.

Code:
(oc_calendar.username = balances.uid) AND
         ($day != DATE_FORMAT(oc_calendar.start_date, '%d')) AND
          ($day != DATE_FORMAT(oc_calendar.end_date, '%d')) AND
           ($month != DATE_FORMAT(oc_calendar.start_date, '%m')) AND
            ($month != DATE_FORMAT(oc_calendar.end_date, '%m')) AND
             ($year != DATE_FORMAT(oc_calendar.start_date, '%Y')) AND
              ($year != DATE_FORMAT(oc_calendar.end_date, '%Y'))

Currently if ANY of the entries are of the same year or month or day it will not return the results. I need it to not return results ONLY if the entry matches the year, day, and month.

How do I go about doing that?

Thanks,
-Ryan
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I'm not quite sure what you are trying to do. You seem to be comparing one date ($day, $month, $year) with 2 dates (start_date and end_date). Is it supposed to match a range? In which case you probably want:

Code:
    (oc_calendar.username = balances.uid) AND
    ($day >= DATE_FORMAT(oc_calendar.start_date, '%d')) AND
    ($day <= DATE_FORMAT(oc_calendar.end_date, '%d')) AND
    ($month >= DATE_FORMAT(oc_calendar.start_date, '%m')) AND
    ($month <= DATE_FORMAT(oc_calendar.end_date, '%m')) AND
    ($year >= DATE_FORMAT(oc_calendar.start_date, '%Y')) AND
    ($year <= DATE_FORMAT(oc_calendar.end_date, '%Y'))

This returns results on a match. To get it to not return results on a match use:

Code:
    (oc_calendar.username = balances.uid) AND NOT
    (($day >= DATE_FORMAT(oc_calendar.start_date, '%d')) AND
     ($day <= DATE_FORMAT(oc_calendar.end_date, '%d')) AND
     ($month >= DATE_FORMAT(oc_calendar.start_date, '%m')) AND
     ($month <= DATE_FORMAT(oc_calendar.end_date, '%m')) AND
     ($year >= DATE_FORMAT(oc_calendar.start_date, '%Y')) AND
     ($year <= DATE_FORMAT(oc_calendar.end_date, '%Y')))
 
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back