从SQL的时间戳获取周数

发布于 2025-02-10 20:16:41 字数 393 浏览 2 评论 0原文

我有一个字段,该字段显示时间戳'mm/dd/yyyy hh:mi:ss'。我试图从该字段中提取ISOWEEK数字,但根据我使用的公式,未能接收错误消息的变体。

嗨,我希望有人可以提供帮助。

我试图从时间戳获得Isoweeknumber。我尝试了以下3个修订,获取不同的错误消息。

to_char(to_date(Datestamp, 'dd/mm/yyyy'), 'iw')
to_char(trunc(Datestamp),'iw')
to_char(trunc(to_date(Datestamp),'iw'), 'dd/mm/yyyy hh24:mi:ss')

我还反转了to_char(to_date(())没有运气。

I have a field which displays a timestamp 'mm/dd/yyyy hh:mi:ss'. I am trying to extract the Isoweek number from this field unsuccessfully receiving a variant of error messages depending on the formula I have used.

Hi, I hope someone can assist.

I am attempting to get the IsoWeeknumber from a Timestamp. I have tried the below 3 revisions getting varying error messages.

to_char(to_date(Datestamp, 'dd/mm/yyyy'), 'iw')
to_char(trunc(Datestamp),'iw')
to_char(trunc(to_date(Datestamp),'iw'), 'dd/mm/yyyy hh24:mi:ss')

I have also reversed to_char(to_date(()) with no luck.

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

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

发布评论

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

评论(3

一百个冬季 2025-02-17 20:16:41

使用与字符串相同的格式(使用HH24用于24小时时钟,而不是HHHH12,用于12小时时钟):

SELECT to_char(to_date(Datestamp, 'MM/DD/YYYY HH24:MI:SS'), 'IW')
FROM   table_name;

db<> fiddle

Use the same format as the string (with HH24 for a 24-hour clock, rather than HH or HH12 which are for 12-hour clocks):

SELECT to_char(to_date(Datestamp, 'MM/DD/YYYY HH24:MI:SS'), 'IW')
FROM   table_name;

db<>fiddle here

﹎☆浅夏丿初晴 2025-02-17 20:16:41

这就是您可以从日期开始提取周数的方式

    select to_char(to_date('01/02/2022','MM/DD/YYYY'),'WW') from dual

This is how you can extract week number from date

    select to_char(to_date('01/02/2022','MM/DD/YYYY'),'WW') from dual
假装不在乎 2025-02-17 20:16:41

随着您的日期和时间

 选择to_char(to_date('01/02/2022 10:10:10','mm/dd/yyyy hh:mi:ss'),'iw')
 
 | to_char(to_date('01/02/202210:10:10','mm/dd/yyyyhh:mi:ss'),'iw')|
| :--------------------------------------------------------------------------- ---------------- |
| 52 |

db&lt;&gt;&gt;

As you have date and time

select to_char(to_date('01/02/2022 10:10:10','MM/DD/YYYY HH:MI:SS'),'IW') from dual
| TO_CHAR(TO_DATE('01/02/202210:10:10','MM/DD/YYYYHH:MI:SS'),'IW') |
| :--------------------------------------------------------------- |
| 52                                                               |

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文