| Buffy | 1989-05-13 | +-------+------------+ 

There is a small complication if the current month is December. You cannot merely add one to the month number ( 12 ) and look for animals born in month 13 , because there is no such month. Instead, you look for animals born in January (month 1 ). 

You can write the query so that it works no matter what the current month is, so that you do not have to use the number for a particular month. DATE_ADD()  enables you to add a time interval to a given date. If you add a month to the value of CURDATE() , then extract the month part with MONTH() , the result produces the month in which to look for birthdays: 

mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH)); 

A different way to accomplish the same task is to add 1  to get the next month after the current one after using the modulo function ( MOD ) to wrap the month value to 0  if it is currently 12 : 

mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1; 

MONTH()  returns a number between 1  and 12 . And MOD(something,12)  returns a number between 0 and 11 . So the addition has to be after the MOD() , otherwise we would go from November ( 11 ) to January ( 1 ). 

## 3.3.4.6 Working with NULL Values 

If a calculation uses invalid dates, the calculation fails and produces warnings: 

mysql> SELECT ’2018-10-31’ + INTERVAL 1 DAY; +-------------------------------+ | ’2018-10-31’ + INTERVAL 1 DAY | +-------------------------------+ | 2018-11-01 | +-------------------------------+ mysql> SELECT ’2018-10-32’ + INTERVAL 1 DAY; +-------------------------------+ | ’2018-10-32’ + INTERVAL 1 DAY | +-------------------------------+ | NULL | +-------------------------------+ mysql> SHOW WARNINGS; +---------+------+----------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------+ | Warning | 1292 | Incorrect datetime value: ’2018-10-32’ | +---------+------+----------------------------------------+ 

The NULL  value can be surprising until you get used to it. Conceptually, NULL  means “a missing unknown value”  and it is treated somewhat differently from other values. 

To test for NULL , use the IS NULL  and IS NOT NULL  operators, as shown here: 

mysql> SELECT 1 IS NULL, 1 IS NOT NULL; +-----------+---------------+ | 1 IS NULL | 1 IS NOT NULL | +-----------+---------------+ | 0 | 1 | +-----------+---------------+ 

You cannot use arithmetic comparison operators such as = , < , or <>  to test for NULL . To demonstrate this for yourself, try the following query: 

