Oracle:如何查找该月的最后一个星期五的日期
问题描述:
有什么办法,我们可以用sql或pl/sql编写查询以查找当前月份的最后一个星期五的日期吗? 在此先感谢!!!
Is there any way, we can write a query in sql or pl/sql to find date of last friday of current month ? Thanks in advance !!!
答
您可以使用LAST_DAY( SYSDATE )
获取该月的最后一天.如果从中减去7天,则可以使用NEXT_DAY()
函数查找该月的最后一个星期五:
You can use LAST_DAY( SYSDATE )
to get the last day of the month. If you subtract 7 days from that then you can use the NEXT_DAY()
function to find the last Friday of the month:
SELECT NEXT_DAY(
LAST_DAY( SYSDATE ) - INTERVAL '7' DAY,
'FRIDAY'
)
FROM DUAL;
如果要将日期截断到当天的午夜,请在TRUNC()
中将其包装.
Wrap it in TRUNC()
if you want to truncate the date to midnight of that day.