如何将年份和月份插入日期字段?(How to insert just year and month into date field?)

系统教程 行业动态 更新时间:2024-06-14 16:52:52
如何将年份和月份插入日期字段?(How to insert just year and month into date field?)

我有一个名为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");

更多推荐

本文发布于:2023-04-05 12:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/9cac3ab5399adafd46dfd9a4f81005ab.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   如何将   年份   日期   insert

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!