Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could store the partial date as an integer (preferably in a field named for the portion of the date you are storing, such as <code>year,</code> <code>month</code> or <code>day</code>) and do validation and conversion to a date object in the model.</p> <p><strong>EDIT</strong></p> <p>If you need real date functionality, you probably need real, not partial, dates. For instance, does "get everything after 2010-0-0" return dates inclusive of 2010 or only dates in 2011 and beyond? The same goes for your other example of May 2010. The ways in which different languages/clients deal with partial dates (if they support them at all) are likely to be highly idiosyncratic, and they are unlikely to match MySQL's implementation.</p> <p>On the other hand, if you store a <code>year</code> integer such as 2010, it is easy to ask the database for "all records with year > 2010" and understand exactly what the result should be, from any client, on any platform. You can even combine this approach for more complicated dates/queries, such as "all records with year > 2010 AND month > 5".</p> <p><strong>SECOND EDIT</strong></p> <p>Your only other (and perhaps best) option is to store truly valid dates and come up with a convention in your application for what they mean. A DATETIME field named like <code>date_month</code> could have a value of 2010-05-01, but you would treat that as representing all dates in May, 2010. You would need to accommodate this when programming. If you had <code>date_month</code> in Python as a datetime object, you would need to call a function like <code>date_month.end_of_month()</code> to query dates following that month. (That is pseudocode, but could be easily implemented with something like the <a href="http://docs.python.org/library/calendar.html" rel="nofollow noreferrer">calendar</a> module.) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload