Created
May 12, 2015 13:52
-
-
Save krusynth/dc17a582fe3e73a16f7d to your computer and use it in GitHub Desktop.
Handling multifield dates. Please don't do this. It's bad - unmanageable, unreadable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> desc testdates; | |
+-------+----------------------+------+-----+---------+----------------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+-------+----------------------+------+-----+---------+----------------+ | |
| id | int(10) unsigned | NO | PRI | NULL | auto_increment | | |
| year | smallint(5) unsigned | YES | | NULL | | | |
| month | tinyint(3) unsigned | YES | | NULL | | | |
| day | tinyint(3) unsigned | YES | | NULL | | | |
+-------+----------------------+------+-----+---------+----------------+ | |
mysql> select * FROM testdates; | |
+----+------+-------+------+ | |
| id | year | month | day | | |
+----+------+-------+------+ | |
| 1 | 2004 | 0 | 0 | | |
| 2 | 2003 | 6 | 5 | | |
| 3 | 2008 | 3 | 21 | | |
| 4 | 2005 | 11 | 0 | | |
+----+------+-------+------+ | |
mysql> SELECT * FROM testdates WHERE (year=2004 AND month>7) OR (year>2004 AND year<2006) OR (year=2006 AND month<6); | |
+----+------+-------+------+ | |
| id | year | month | day | | |
+----+------+-------+------+ | |
| 4 | 2005 | 11 | 0 | | |
+----+------+-------+------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment