如何将 mysql 日期戳字段分为年、季度、月和日

发布于 2024-11-15 21:52:01 字数 206 浏览 3 评论 0原文

我有一个 mysql 数据库,其中有一个用于条目的日期戳字段。我真的很想将年、季度、月和日分成单独的列。我可以毫无问题地创建新列,但我不知道如何编写一个可以轻松完成此操作的查询。我一直在玩这样的事情

SELECT MONTH();
FROM `datestamp`

,但没有任何快乐......

感谢任何帮助:-)

I have a mysql database with a datestamp field for entries. I'd really like to separate out the year, quarter, month and day into individual columns. I can make the new columns without a problem but I don't know how to write a query that does this easily. I've been playing around with things like this

SELECT MONTH();
FROM `datestamp`

But haven't had any joy...

Any help gratefully received :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦冥 2024-11-22 21:52:01

这应该让你开始...

SELECT DAY(`datestamp`) AS `day`,
       MONTH(`datestamp`) AS `month`,
       YEAR(`datestamp`) AS `year`,
       QUARTER(`datestamp`) AS `quarter`
  FROM `table`;

This should get you started...

SELECT DAY(`datestamp`) AS `day`,
       MONTH(`datestamp`) AS `month`,
       YEAR(`datestamp`) AS `year`,
       QUARTER(`datestamp`) AS `quarter`
  FROM `table`;
再浓的妆也掩不了殇 2024-11-22 21:52:01

这应该有效:

SELECT MONTH(`datestamp`) AS `datemonth`, 
DAY(`datestamp`) AS `dateday`,
YEAR(`datestamp`) AS `dateyear`,
QUARTER(`datestamp`) AS `datequarter`
FROM `table`;

This should work:

SELECT MONTH(`datestamp`) AS `datemonth`, 
DAY(`datestamp`) AS `dateday`,
YEAR(`datestamp`) AS `dateyear`,
QUARTER(`datestamp`) AS `datequarter`
FROM `table`;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文