我有一个名为table_date的列,目前我正在使用now()插入当前日期( 2011-02-23 )。 我知道我可以用sql / php操作这个来显示我的年份和月份名称。 但是,我想知道是否有可能在2011-02年2月之前插入到table_date当前日期中作为年 - 月? 谢谢
I have a column called table_date which currently I am using now() to insert the current date (2011-02-23). I know I can manipulate this with sql/php to show me year and monthname. However, I want to know if it's possible to just insert into table_date the current date as year-month like this 2011-02? Thanks
最满意答案
DATE字段始终是一个完整的日期,并且据我所知,它也总是需要指定一个完整的日期。
使用01可能最容易,比如2011年2月的2011-02-01 。
显然,您可以在查询时根据自己的喜好格式化DATE字段的输出:
SELECT DATE_FORMAT(fieldname,"%Y-%m");A DATE field is always going to be a full date, and as far as I know, it is also always required to specify a full date.
It might be easiest to use 01, like 2011-02-01 for February 2011.
Obviously, you can format the output of a DATE field to your liking when querying it:
SELECT DATE_FORMAT(fieldname,"%Y-%m");更多推荐
发布评论