Get start and end week date by month and year
How I need the week is by this -- a week always starts on a sunday so for feburary it will be
start week end week
12-02-1 12-02-04
12-02-05 12-02-11
12-02-12 12-02-18
12-02-19 12-02-25
12-02-26 12-29-29
So because the first week does not start on a sunday it goes from
1(wednesday) to 4th(saturday) Just like a calendar.
Thanks in advance
so far from Solomons help I have this
This is for january
WITH t AS (
SELECT TRUNC(TRUNC(to_date('01-01-12','MM-DD-YY'),'YYYY') -1,'W') + (LEVEL-1 ) * 7 week_start_date
FROM DUAL
CONNECT BY LEVEL <= 53
SELECT week_start_date,
LEAST(LAST_DAY(to_date('01-01-12','MM-DD-YY')),week_start_date + 6) week_end_date
FROM t
WHERE week_start_date >= TRUNC(to_date('01-01-12','MM-DD-YY'),'MM')
AND week_start_date < ADD_MONTHS(TRUNC(to_date('01-01-12','MM-DD-YY'),'MM'),1)
start week end week
12-01-02 12-01-08
12-01-09 12-01-15
12-01-16 12-01-22
12-01-23 12-01-29
12-01-30 12-01-31
If week satrts Sunday:
WITH t AS (
SELECT TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 week_start_date
FROM DUAL
CONNECT BY TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 <= LAST_DAY(&dt)
SELECT GREATEST(week_start_date,TRUNC(&dt,'MM')) week_start_date,
LEAST(LAST_DAY(&dt),week_start_date + 6) week_end_date
FROM t
WHERE week_start_date <= LAST_DAY(&dt)
/For example:
SQL> SET VERIFY OFF
SQL> DEFINE dt="DATE '2012-01-17'" -- January
SQL> WITH t AS (
2 SELECT TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 week_start_date
3 FROM DUAL
4 CONNECT BY TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 <= LAST_DAY(&dt)
5 )
6 SELECT GREATEST(week_start_date,TRUNC(&dt,'MM')) week_start_date,
7 LEAST(LAST_DAY(&dt),week_start_date + 6) week_end_date
8 FROM t
9 WHERE week_start_date <= LAST_DAY(&dt)
10 /
WEEK_STAR WEEK_END_
01-JAN-12 07-JAN-12
08-JAN-12 14-JAN-12
15-JAN-12 21-JAN-12
22-JAN-12 28-JAN-12
29-JAN-12 31-JAN-12
SQL> SET VERIFY OFF
SQL> DEFINE dt="DATE '2012-02-25'" -- February
SQL> WITH t AS (
2 SELECT TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 week_start_date
3 FROM DUAL
4 CONNECT BY TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 <= LAST_DAY(&dt)
5 )
6 SELECT GREATEST(week_start_date,TRUNC(&dt,'MM')) week_start_date,
7 LEAST(LAST_DAY(&dt),week_start_date + 6) week_end_date
8 FROM t
9 WHERE week_start_date <= LAST_DAY(&dt)
10 /
WEEK_STAR WEEK_END_
01-FEB-12 04-FEB-12
05-FEB-12 11-FEB-12
12-FEB-12 18-FEB-12
19-FEB-12 25-FEB-12
26-FEB-12 29-FEB-12
SQL> SET VERIFY OFF
SQL> DEFINE dt="DATE '2012-03-07'" -- March
SQL> WITH t AS (
2 SELECT TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 week_start_date
3 FROM DUAL
4 CONNECT BY TRUNC(TRUNC(&dt,'MM') + 1,'IW') - 1 + (LEVEL - 1) * 7 <= LAST_DAY(&dt)
5 )
6 SELECT GREATEST(week_start_date,TRUNC(&dt,'MM')) week_start_date,
7 LEAST(LAST_DAY(&dt),week_start_date + 6) week_end_date
8 FROM t
9 WHERE week_start_date <= LAST_DAY(&dt)
10 /
WEEK_STAR WEEK_END_
01-MAR-12 03-MAR-12
04-MAR-12 10-MAR-12
11-MAR-12 17-MAR-12
18-MAR-12 24-MAR-12
25-MAR-12 31-MAR-12
SQL> SY.
Edited by: Solomon Yakobson on Jan 12, 2012 1:19 PM
Similar Messages
-
FM to get start and end date when given month
Hi all,
can anybody help me if there a FM to get start and end date when given month like 01 for jan.
Thanks in advance
SahityaHi,
Check this Function Module
HR_JP_MONTH_BEGIN_END_DATE
here if you r giving the month u wil get the start date and the end date.
Hope this helps you.
Thanks & regards,
Y.R.Prem Kumar -
My left shift key on Macbook Pro Retina (15") is behaving like the F11 key (show/hide open windows).
The left shift key behaves the same on the laptop keyboard and on an external Apple keyboard.
This just started in last week after 6 months of use. The right shift key and other keys on the keyboard all appear to work correctly.
Suggestions greatly appreciated.I have a solution to this issue now after a discussion with Apple Support. Some where in the last few weeks, there was a change in the key that would do a Show Desktop under the Mission Control settings in the System Preferences. Even though the key sequence that was shown for the Show Desktop setting did not include the Left SHift key, by changing this first to having no key sequence and applying that and then changing it back to the F11 key, the Left SHift key issue that I was having has cleared up.
A second issue that was uncovered was that the SSD had some issues (uncovered when I ran Disk Utility using the Repair Disk key). I had to restart and use the Disk Utility through the Command R sequence to get to the stand alone Disk Utility. The SSD appears to be running better as a result as well.
Hope that this is of use to someone else in the future. -
i chose an option which replaced 'bookmarks' in the menu with most visited, getting started and latest headlines. I want to go back to the default, simply 'Bookmarks' How do I do this?
<u>'''Can't see the Menu Bar'''</u> (File, Edit, View, History...Help)? Hold down the key ( key in OSX) and press the following letters in this exact order: V T M
The Menu Bar should now be displayed permanently, unless you turn it off again (View > Toolbars). Turning the Menu Bar on and off is a new feature in version 3.6.
See: http://support.mozilla.com/en-US/kb/Menu+bar+is+missing
<u>'''See other Toolbars'''</u> under View > Toolbars. Clicking on one of them will place a check mark (display) or remove the check mark (not displayed).
<u>'''To display the Status Bar'''</u>, View, then click Status bar to place a check mark (display) or remove the check mark (not displayed).
<u>'''Full Screen mode'''</u>
http://kb.mozillazine.org/Netbooks#Full_screen
Also see:
''' [[Back and forward or other toolbar buttons are missing]]'''
'''[[Navigation Toolbar items]]''' -
I am trying to get started and register my new ipad. I have been told to sign into " my info web page". How do I do that and where do I find it?
Hi,
You can register your new iPad here.
https://register.apple.com/cgi-bin/WebObjects/GlobaliReg.woa
Carolyn :-) -
apple phone 3g is not getting started and i can find only apple logo when connected to system and my system is not recognizing the mobile device. kindly help me in this regard
Put the device in DFU mode (google it) and restore as new.
-
Hello, i am just getting started and i cant seem to get connected to wifi
hello, i am just getting started and i cant seem to get connected to wifi
bulitog wrote:
so... if on my wifi network stays at "choose a network" does that mean there is not an open wifi availble?
If there is a list to choose from those are the names of the available wifi networks that are visible to your iPad's wifi. Some of them will be locked, you will need the password to connect to these. Some will be unlocked(open), you will not need a password to connect to these.
If it is your own wifi network then do not leave it open. Set up a name and password in your wifi router. It will show up in your list to choose from. You then provide the password you set in the router when asked for the password. -
Getting started and Help & Support pages in several languages
A whole batch of new pages just got published in non-English languages. See here for information in English, Deutsch, Français, 日本語, Español, and Italiano:
"Getting started and Help and Support pages in several languages"gracias !
Ciao ! -
Getting Start and End Date of Current Year?
Hi Folks,
How do I get the start of the year and end of the year in Java ?
If I say :
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
System.out.println("Day: " + day);
System.out.println("Month: " + month);
System.out.println("Year: " + year);
I get the current day and time.What I need is the start of the current Year (Jan 2010) and the End of the Current Year (Dec 2010).
How can get the above 2 dates if I the current date is March 24th 2010 ?
Thankssabre150 wrote:
What am I missing? The start date of 2010 is 1/1/2010 and the end data is 31/12/2010 . So, as I see it, at any time the only information you need is the current year which you currently get from int year = cal.get(Calendar.YEAR);
Well, with the GregorianCalendar, anyway. ;-) -
Return the end of week date using month and week number
Hi all,
I am trying to find the date for end of the week using given month (201401, 201402...i.e, 2014 is year and 01,02 are months) and week number (01,02,03...) for the year. For example if my month is 201402 and week_number is 06 then it return the week_date
as 2014-02-08. Can you please help me in writing a sql statement for this scenario.
Thanks in advance,
NikhilCurrent month is irrelevant
with dt as (
select dateadd(day, (6-1)*7, '2014-01-01') as xwk
select dateadd(day, 7-datepart(weekday, dt.xwk), xwk)
from dt;
Change the "6" in the with statement to the week of interest and 2014 to the year of interest... -
How to get start and end time of an ESB instance in SOA 10.1.3.4
Hi All,
I am using soa 10.1.3.4 and want to track the esb instance start and end time. (For example, in case of bpel we can query the cube instance table to get creation and modify time of an instance. )
How to get that in esb?
Thank you.
Regards,
SatishHi Satish
You may enable instance tracking option on the ESB Console and track the instances audit information and also from the logs(log.xml) when ESB loggers are set to DEBUG mode.
Regards
A -
Get Start and End times for each step in a job
Can someone tell me how to get the start and end times for each step in a background job? Table TBTCP only stores the time that the step was saved in a background job. Table TBTCO stores the times for the entire job and not each individual step.
Thanks.
RyanHi,
Please check this tables and FM perhaps they may help
TBTCJSTEP - Background Job Step Overview
TBTCR - Batch scheduler execution time
TBTCS - Background Processing: Time Schedule Table
GET_JOB_RUNTIME_INFO
Regards,
Ferry Lianto -
How do you get start and end times to show
is there a way the start and finish times of each event daily will show on the monthly view of Ical
AFAIK only the start time can show. (Preferences>General, check 'Show event times in Month View'.)
-
I woke up this morning and found my iPhone 4 is off condition, With the assumption that is needs to be charged, I tried to hook up for charging, I haven't succeed in this attempt, The phone is not getting started, even i charge it, Help me out.
Try a reset:
- hold the home button and sleep/wake button down at the same time for atleast 15 seconds
- if you see the Apple logo appear rlease both buttons
If that fails try charging the iPhone while plugged into the wall adaptor and also while plugged into the computer. Try cahrging both ways for atleast 15-20 minutes. Also while its plugged into the computer check and see if the computer or iTunes will recognise that the iPhone is connected. -
Function to find the Last Date of Month One Year Ago - RETURNS ERROR
I've written sql code which takes a date and finds the Last Day of the Month one year ago. For example, it takes the date '2015-04-17' and returns the date '2014-04-30'. The code works fine in a query. Now I'm trying to turn this into a function. However,
when I try to create the function I get the error:
Operand type clash: date is incompatible with int
Why is this error being returned?
Here is my function:
CREATE FUNCTION dbo.zEOM_LY_D(@Input Date)
RETURNS date
AS
BEGIN;
DECLARE @Result date;
SET @Result = convert(DATE, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,dateadd(m, -11, @Input)+1),0)),101)
RETURN @Result;
END;
Thanks for any help you can give.
Stan,
Thanks very much- that does the trick. I should have said I am using SQL 2008 so EOMONTH is not available to me. I still don't get why I got an error though, since I was treating a date like a date and not like an int.
Thanks, John
I think i found the issue but i do not know why it is causing the issue. i think may be the way dates are treated/stored internally..i think dates are stored as no of days after 0001/01/01 but cannot see how this cwould effect..may be somebody else can through
some light.....
if you make it as datetime it will work,
if you leave it as date - eliminate adding 1... you should prefer to use dateadd to add/substract dates.
try this to understand..
--removed the +1 in the code
declare @input date
set @input ='20150503'
select
convert(DATE, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,dateadd(m, -11, @Input)),0)),101)
go
--made the datatype as datetime
declare @input datetime
set @input ='20150503'
select
convert(DATE, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,dateadd(m, -11, @Input)+1),0)),101)
Hope it Helps!!
Maybe you are looking for
-
TOC Not Appearing in Help Running on Mac
I have created a Help project in WebHelp to run with a Mac application. When the file is opened on the Mac, the TOC does not appear. Can anyone help me out with this one? We are set to release this project in the next few days, so I need an answer AS
-
Possibility to assign a color profile in the color management tab for more video formats
Presently, in After Effects CS5, in the color management tab of the "Interpret Footage" dialog box the possibility to assign a color profile to footage is grayed out for many video formats. Formats that allow to assign a color profile include Quickti
-
8.1.7 Corruption?
On an Oracle 8.1.7 database on win2000 server received the following in the alrt.bms Wed Oct 05 19:25:06 2005 KCF: write/open error block=0x438b online=1 file=3 D:\ORACLE\ORADATA\BMS\USR01.DBF error=27070 txt: 'OSD-04016: Error queuing an asynchronou
-
What is going on here. I've waited 4 weeks for my ipad which will not do anything untill I've downloaded the latest version of itunes which I can't do because this message keeps appearing, Our apologies but there was an unexpected error with the appl
-
Securing DSP calls via Web Services Mediator API
I have been implementing a client of DSP 3.0 services using the static Web Services Mediator API. I am successfully calling these through the AL Service Bus, where I have deployed the WSDL generated from the DSP. We are calling this from a rich clien