mysql数据类型仅存储月份和年份 [英] mysql datatype to store month and year only

查看:1863
本文介绍了mysql数据类型仅存储月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个将STUDENT数据存储在MySQL关系数据库中的php应用程序。我试图找到最好的方式/数据类型,以保存一个月和一年没有一天。我不知道我是否应该将它存储为DATE,并且使用php将某天作为第一个,或者使用我目前不熟悉的其他数据类型。理想情况下,我不想存储一天,因为一天不会总是一样的,如果将来更改日期,需要更改php源代码。



只是为了更多的背景信息,我正在存储一个学生的INTENT_TO_GRAD。客户端似乎只希望此信息作为参考或报表的视觉效果,而不是将其用于数据操作。换句话说,这个数据的唯一功能要求是显示在报表中。

解决方案

为什么要打扰?只需将其存储为完整的日期(可能总是使用第一个当天),并使用数据库函数 MONTH() YEAR() ,如果您只需要部分的。这使得使用该字段更容易,因为您仍然可以进行范围查询等。


I'm writing a php application that will store STUDENT data in a MySQL relational database. I'm trying to find the best way/datatype to store a month and year together without the day. I don't know whether I should just store it as a DATE and use php someway to just store the day as the 1st or use a different datatype that I'm not currently familiar with. Ideally, I do not want to store a day, because the day will not always be the same and would require changing php source code if the day changed in the future.

Just for more background info, I'm storing a STUDENT's INTENT_TO_GRAD. The client seems to only want this information as a reference or a visual for a report as opposed to using it for data manipulation. In other words, the only functional requirement for this data is to be displayed in a report.

解决方案

Why bother? Just store it as a complete date (perhaps always using the first as the day) and use the database functions MONTH() and YEAR() if you only need part of it. This makes using that field much easier as you can still do range queries, etc.

这篇关于mysql数据类型仅存储月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆