在Firebird 3中,一周的最后一天日期是什么?

huangapple go评论79阅读模式
英文:

Date of last day of week in Firebird 3

问题

这是在Firebird 3中获取星期第一天(星期一)的日期的代码:

DATEADD(DAY, (EXTRACT(WEEKDAY FROM D - 1) * -1), D)

要获取星期的最后一天(星期日)的日期,可以使用以下代码:

DATEADD(DAY, (6 - EXTRACT(WEEKDAY FROM D)), D)

在Firebird中,星期的表示方式是:星期一(Mon)= 1,星期二(Tues)= 2,...,星期日(Sun)= 0。

英文:

This is a date of first day of week (monday) in Firebird 3:

DATEADD(DAY, (EXTRACT(WEEKDAY FROM D - 1) * -1), D)

And how to get the date of the last day of the week (Sunday)?

In Firebird: Mon = 1, Tues = 2, ... Sun = 0.

答案1

得分: 2

对于 ISO-8601 周,其中星期一是一周的第一天,您还可以使用以下代码确定星期一:

dateadd(day, 0 - mod(extract(weekday FROM d) + 6, 7), d)

使用 mod(extract(weekday FROM d) + 6, 7) 将使星期一为 0,星期二为 1,依此类推,星期日为 6,以便进行更容易的计算。

然后,您可以使用以下代码确定星期日:

dateadd(day, 6 - mod(extract(weekday FROM d) + 6, 7), d)

您可以轻松地使用类似的方法确定其他一周中的天(例如,使用 1 - mod(extract(weekday FROM d) + 6, 7) 来确定星期二等)。

另一方面,如果星期日是一周的第一天(例如,在美国),您可以使用以下代码:

dateadd(day, 0 - extract(weekday from d), d)

以及星期一的代码:

dateadd(day, 1 - extract(weekday from d), d)
英文:

For ISO-8601 weeks, where Monday is the first day of the week, you can also determine Monday using:

dateadd(day, 0 - mod(extract(weekday FROM d) + 6, 7), d)

The use of mod(extract(weekdays from d) + 6, 7) will make Monday 0, Tuesday 1, etc and Sunday 6 to make the calculations easier.

You can then determine Sunday using:

dateadd(day, 6 - mod(extract(weekday FROM d) + 6, 7), d)

You can easily derive other days of the week this way (eg use 1 - mod(extract(weekday FROM d) + 6, 7) for Tuesday, etc.

On the other hand, if Sunday is the first day of the week (eg as in the US), you can use:

dateadd(day, 0 - extract(weekday from d), d)

and for Monday

dateadd(day, 1 - extract(weekday from d), d)

huangapple
  • 本文由 发表于 2020年1月6日 18:35:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610547.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定