简体   繁体   English

从SQL中的日期获取星期

[英]getting week from the date in sql

I want to how i can split the month into respective weeks based on the user entry, like from 1day of the month or by first week of the week. 我想根据用户输入将月份分为各个星期,例如从每月的1天开始,还是从一周的第一周开始。

example: if user wants data based on 1day of the month ie, 01-06-2012 then 例如:如果用户想要基于当月1天(即2012年1月6日)的数据,则

jun'2012 1/6-7/6 8/6-14/6 15/6-21/6 22/6-28/6 29/6-30/6 2012年6月1 / 6-7 / 6 8 / 6-14 / 6 15 / 6-21 / 6 22 / 6-28 / 6 29 / 6-30 / 6

if the user wants according to first week ie, 4-6-2012 如果用户希望按照第一周的要求,即2012年4月6日

jun-2012 4-10 11-17 18-24 2012年6月4-10 11-17 18-24
i think this will be a fiscal week 我认为这将是一个财政周

can anyone please tell me how i can get this? 谁能告诉我我怎么能得到这个?

and how to get the complete week based on the given date 以及如何根据给定的日期获得完整的一周

This could give u an idea, 这可以给你一个主意,

declare
vdate date := sysdate;  
temp  Date;
begin
temp  :=  VDate;
WHILE last_day(temp) >=  vDate
LOOP
   dbms_output.put_line(to_char(vDate));
   vDate := vDate+7;
END LOOP;
end;

end;

The result will be starting from to day (10th Dec 2012) to the last day of this week 结果将从当天开始(2012年12月10日)到本周的最后一天

    10-DEC-12
    17-DEC-12
    24-DEC-12
    .....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM