guagay_wk
guagay_wk

Reputation: 28030

What is an appropriate value to store in a DATE MySQL variable if only month and year are known?

Suppose I have a MySQL variable date_stored of date datatype. I have only the month and year for a particularly date data to be stored in date_stored. No day information is given. Are there guidelines on what to store in date_stored if only month and year are known?

Upvotes: 1

Views: 111

Answers (1)

I Bajwa PHD
I Bajwa PHD

Reputation: 1756

MySQL manual says that partial dates can be stored. Month and day Ranges specifiers begin with zero because MySQL permits incomplete dates storing such as '2015-00-00' or '2015-10-00'. http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

So if day part is not given you can still store it as YYYY-MM-00 e.g '2015-10-00'

Also See below related posts.

Store incomplete date in MySQL date field

mysql datatype to store month and year only

SQL DataType - How to store a year?

Upvotes: 2

Related Questions