How to get the week number for a given date?
hi guys,
what is coding to get the week number for a given date?
For example, 1/1/05 is week 1. then 8/1/05 is week 2.
The second parameter to pass to the method is supposed to be one of the month constants JANUARY - DECEMBER. It happens to be that their numerical values are 0-11, not 1-12, so your "12" refers to the "13th" month of the year.
givenDate = new GregorianCalendar(2003, Calendar.DECEMBER, 31);
If you want to construct dates and times from strings like you seem to be, look into SimpleDateFormat http://javaalmanac.com/egs/java.text/ParseTime.html
(even still I got WEEK_OF_YEAR as 1 which is true but not really what I expected, excuse my previous reply but I wanted to check the facts before posting this)
Similar Messages
-
Getting the week number for a given date
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 64-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
Hello all.
I am currently migrating our product from SQL SERVER to ORACLE and have the following issue.
Basically I'm just trying to get the year week number for a given date but I'm having trouble with Oracle as it seems to think that the weeks run from Thursday to Thursday?. I presume this is something to do with the fact that the first day of the year was Thursday?
e.g.
SQL SERVER:
select DATEPART(wk, '2009-10-24') as Sat -- 43 - correct
select DATEPART(wk, '2009-10-25') as Sun -- 44 - correct
select DATEPART(wk, '2009-10-26') as Mon -- 44 - correct
select DATEPART(wk, '2009-10-27') as Tue -- 44 - correct
select DATEPART(wk, '2009-10-28') as Wed -- 44 - correct
select DATEPART(wk, '2009-10-29') as Thu -- 44 - correct
select DATEPART(wk, '2009-10-30') as Fri -- 44 - correct
select DATEPART(wk, '2009-10-31') as Sat -- 44 - correct
select DATEPART(wk, '2009-11-1') as Sun -- 45 - correct
select DATEPART(wk, '2009-11-2') as Mon -- 45 - correct
select DATEPART(wk, '2009-11-3') as Tue -- 45 - correct
select DATEPART(wk, '2009-11-4') as Wed -- 45 - correct
select DATEPART(wk, '2009-11-5') as Thu -- 45 - correct
ORACLE:
SELECT to_char(to_date('24-OCT-2009'), 'ww') as Sat from dual; -- 43 correct
SELECT to_char(to_date('25-OCT-2009'), 'ww') as Sun from dual; -- 43 incorrect - should be 44
SELECT to_char(to_date('26-OCT-2009'), 'ww') as Mon from dual; -- 43 incorrect - should be 44
SELECT to_char(to_date('27-OCT-2009'), 'ww') as Tue from dual; -- 43 incorrect - should be 44
SELECT to_char(to_date('28-OCT-2009'), 'ww') as Wed from dual; -- 43 incorrect - should be 44
SELECT to_char(to_date('29-OCT-2009'), 'ww') as Thu from dual; -- 44 correct
SELECT to_char(to_date('30-OCT-2009'), 'ww') as Fri from dual; -- 44 correct
SELECT to_char(to_date('31-OCT-2009'), 'ww') as Sat from dual; -- 44 correct
SELECT to_char(to_date('1-NOV-2009'), 'ww') as Sun from dual; -- 44 incorrect - should be 45
SELECT to_char(to_date('2-NOV-2009'), 'ww') as Mon from dual; -- 44 incorrect - should be 45
SELECT to_char(to_date('3-NOV-2009'), 'ww') as Tue from dual; -- 44 incorrect - should be 45
SELECT to_char(to_date('4-NOV-2009'), 'ww') as Wed from dual; -- 44 incorrect - should be 45
SELECT to_char(to_date('5-NOV-2009'), 'ww') as Thu from dual; -- 45 correct
Now I don't want to get into a discussion with regard to locales etc.
In my world (and is seems SQL SERVER's) the first day of the week is Sunday and the last Saturday.
Is there some NLS_? setting or something that I'm missing?
thanks for any help on this.
AndyThis is what you need.
SELECT ceil(( 7+(trunc(to_date('25-OCT-2009'),'d')-trunc(to_date('25-OCT-2009'),'Y')) )/7) FROM dual
HTH!!!
--tested all these statements.
Works as you wish!!
SELECT ceil(( 7+(trunc(to_date('24-OCT-2009'),'d')-trunc(to_date('24-OCT-2009'),'Y')) )/7) as Sat from dual;
SELECT ceil(( 7+(trunc(to_date('25-OCT-2009'),'d')-trunc(to_date('25-OCT-2009'),'Y')) )/7) as Sun from dual;
SELECT ceil(( 7+(trunc(to_date('26-OCT-2009'),'d')-trunc(to_date('26-OCT-2009'),'Y')) )/7) as Mon from dual;
SELECT ceil(( 7+(trunc(to_date('27-OCT-2009'),'d')-trunc(to_date('27-OCT-2009'),'Y')) )/7) as Tue from dual;
SELECT ceil(( 7+(trunc(to_date('28-OCT-2009'),'d')-trunc(to_date('28-OCT-2009'),'Y')) )/7) as Wed from dual;
SELECT ceil(( 7+(trunc(to_date('29-OCT-2009'),'d')-trunc(to_date('29-OCT-2009'),'Y')) )/7) as Thu from dual;
SELECT ceil(( 7+(trunc(to_date('30-OCT-2009'),'d')-trunc(to_date('30-OCT-2009'),'Y')) )/7) as Fri from dual;
SELECT ceil(( 7+(trunc(to_date('01-NOV-2009'),'d')-trunc(to_date('01-NOV-2009'),'Y')) )/7) as Sat from dual;
SELECT ceil(( 7+(trunc(to_date('02-NOV-2009'),'d')-trunc(to_date('02-NOV-2009'),'Y')) )/7) as Sun from dual;
SELECT ceil(( 7+(trunc(to_date('03-NOV-2009'),'d')-trunc(to_date('03-NOV-2009'),'Y')) )/7) as Mon from dual;
SELECT ceil(( 7+(trunc(to_date('04-NOV-2009'),'d')-trunc(to_date('04-NOV-2009'),'Y')) )/7) as Tue from dual;
SELECT ceil(( 7+(trunc(to_date('05-NOV-2009'),'d')-trunc(to_date('05-NOV-2009'),'Y')) )/7) as Wed from dual;
SELECT ceil(( 7+(trunc(to_date('06-NOV-2009'),'d')-trunc(to_date('06-NOV-2009'),'Y')) )/7) as Thu from dual;
Cheers!!!
Bhushan
Edited by: Buga on Oct 29, 2009 10:46 AM -
How to get the document number for a ware house order.
Hello gurus,
how to get the document number for a ware house order. [if GI is posted refering that WH order] .. is there any report?
Thanks in advanceThere are several options. When you post a Goods Movement, you can use LB12 -display Transfer Requirement for material document or LB11 Display TR for material.
Depending on how your system is set up you may have gotten a Transfer Order automcatically. In this case you can look at LT24 - Transfer Order for material. -
How to get the delivery number for the sales order
hi
how to get the delivery number for the sales orderHi,
1. IN VA03, enter the sales order and click on the document flow button. From there you can check the delivery document.
2. In SE11, enter VBFA(Document flow) table and enter the sales order in VBELV field and in VBTYP_N field enter 'J' to specify that you want to check if there is already a delivery document for that sales order.
Hope it helps...
P.S. Please award points if it helps... -
How to get a week number for the year using oracle sql query?
hi everyone,
i have the requirement to find the week number for the calender..
so that week number should start with 01 when the year starts and it should end with week end date(that is first saturday of the january month).. so next week number starts with sunday and ends with saturday ,continously.. in the end date of the year it should not be 'saturday' but week number should end with last date of the year.. again in the next year it should start with '01'.
for example:
01-JAN-13 tuesday 01
02-JAN-13 wednesday 01
03-JAN-13 thursday 01
04-JAN-13 friday 01
05-JAN-13 saturday 01
06-JAN-13 sunday 02
07-JAN-13 monday 02
26-DEC-13 thursday 52
27-DEC-13 friday 52
28-DEC-13 saturday 52
29-DEC-13 sunday 53
30-DEC-13 monday 53
31-DEC-13 tuesday 53
01-JAN-14 wednesday 01
02-JAN-14 thursday 01
how can i achieve this, can anyone please help me out on this..
i have a query that starts with 01 when year starts but it gives problem in the end of the year .. described below with a query..
select mydate,
to_char(mydate,'day') as weekday,
to_char(next_day(mydate,'sunday'),'iw') as week_num
FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
FROM dual
CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
- TRUNC (SYSDATE, 'yy')
FROM DUAL))
this query gives date, weekday and week_num for 2 years 2013 and 2014,
when i run this query ,at the end of the 2013 it gives the result as,
26-DEC-13 thursday 52
27-DEC-13 friday 52
28-DEC-13 saturday 52
29-DEC-13 sunday 01
30-DEC-13 monday 01
31-DEC-13 tuesday 01
01-JAN-14 wednesday 01
02-JAN-14 thursday 01
for dates 29 ,30,31st it should give 53 .. how can i achieve that using this this query .. can any one help me out on this please...
thanks,
pradeepI tried with the IW ...
it is giving week_id for the year.
select
mydate,
to_char(mydate,'day'),
case when mydate between trunc(mydate,'yyyy') and next_day(trunc(mydate,'yyyy'),'saturday')
then to_number(to_char(mydate,'yyyy')||to_char(trunc(mydate,'yyyy'),'iw'))
when mydate between next_day(trunc(mydate,'yyyy'),'saturday') and trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1
then to_number(to_char(mydate,'yyyy')||to_char(next_day(mydate,'sunday'),'iw'))
when mydate between trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d') and add_months(trunc(mydate,'yyyy'),12)-1
then to_number(to_char(mydate,'yyyy')||to_char(trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1,'iw')+1) end as WEEK_ID
FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
FROM dual
CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
- TRUNC (SYSDATE, 'yy')
FROM DUAL
)) -
Get week number for any given date
How to get a week number in Java?
/ ====================================================
Method: Get the desired Date format for the date
Developed By: Sandip Waghole [29-Jan-2010]
==================================================== /
public String getWeekNo(String strDate)
// input Date Format : M/dd/yyyy
int weekNo=0,i=0;
String strWeekNo=null;
int noOfDaysInTheYear=365;
int WEEK_STARTS_ON = 1; // Define the day on which week starts Sunday/Monday 1:Sunday 2:Monday
int firstDayNoInFirstWeekOfPresentYear=0; // Inititalize teh day on which week is starting in present year
int firstDayOfPresentYear=0; // Inititlize the 1st day of the present year whether Sunday/Monday/.....
int[] monthDaysArray = {31,28,31,30,31,30,31,31,30,31,30,31}; // Define array of the days as per months
int todaysDayNoInPresentYear=0;
int daysLateByFirstWeekStartedAfterYearStarted=0;
int intTemp=0;
//strDate="08/24/2000"; // For test purpose
StringTokenizer strDateTok = new StringTokenizer(strDate, "/ ");
int month = Integer.parseInt(strDateTok.nextToken());
int day= Integer.parseInt(strDateTok.nextToken());
int year = Integer.parseInt(strDateTok.nextToken());
GregorianCalendar cal = new GregorianCalendar();
// Check if present year is leap year
boolean boolIsLeapYear = cal.isLeapYear(year);
// If it is boolean year then add 1 to total days in the year & add one more day to february
if(boolIsLeapYear)
noOfDaysInTheYear=noOfDaysInTheYear+1;
monthDaysArray[1]=monthDaysArray[1]1;
// Find the 1st day of this year
Calendar calObj = new GregorianCalendar(year, Calendar.JANUARY, 1);
firstDayOfPresentYear = calObj.get(Calendar.DAY_OF_WEEK);
int intRemoveNoOfDaysFromWeek=0;
// # Find the day no of prsent day
for(i=0;i<month;i+) // get no of days till present year
intTemp = intTemp monthDaysArray;
todaysDayNoInPresentYear = intTemp - (monthDaysArray[month-1]-day);
if(firstDayOfPresentYear==6 || firstDayOfPresentYear==7) // If first Day is Friday or Saturday then it is week
// Identify the the day no on which 1st week of present year is starting
firstDayNoInFirstWeekOfPresentYear = 7 - firstDayOfPresentYear WEEK_STARTS_ON 1;
// Find delay in the 1st week start after r=the year start
daysLateByFirstWeekStartedAfterYearStarted = firstDayNoInFirstWeekOfPresentYear - 1;
// Now week is starting from Sunday
weekNo = (Integer)((todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted)/7);
// Find the day no of today
intTemp = (todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted) % 7;
if(intTemp > 0)
weekNo=weekNo+1;
else
weekNo=weekNo;
else
// 1st week is starting on 1st Of January
firstDayNoInFirstWeekOfPresentYear=firstDayOfPresentYear;
// Remove no. of days from the 1st week as week is starting from odd Sunday/Monday/Tuesday/Wednesday/Thursday
intRemoveNoOfDaysFromWeek = 7-firstDayOfPresentYear 1; // 1 added as include start day also
// So one week will be added in no. of weeks
weekNo = (Integer)((todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek)/7);
// Find the day no of today
intTemp = (todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek) % 7;
weekNo = weekNo +1; // As 1st weeks days are reduced from the todays day no in the year
if(intTemp > 0)
weekNo=weekNo+1;
else
weekNo=weekNo;
// Remove the no. of days from the week 1
strWeekNo=Integer.toString(weekNo);
return strWeekNo;
// Any issues please mail on [email protected] -
How to get the week number of year from a Date object?
Hi!
I would like to know the week number of the year from a specified Date.
I dont know how to set the first day of week, and set the minimum days of a week.
I want to use Monday for first day of week, and at least 4 days of month in a week.
For example if its 1st, January is Friday, then the first week starts on 4th, Monday.
Anyone can help?Sorry. I should think before I move.
public static int getWeekOfYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
return calendar.get(Calendar.WEEK_OF_YEAR);
} -
How to get the serial number for bundled software (sony vaio notebook)
Hi, bought a laptop from sony (vaio fit (multiflip) 11a and it had photoshop elements preinstalled. I want now a clean, fresh windows and will so reinstall windows from a clean image. but then i wont have photoshop elements, so i need the serial number for my preinstalled photoshop elements. i registerd it online via my adobe id, but it wont show up there. i could extract a key, with belarc adviser (software) but this key does not work if i try to download the trial from adobe.com and try to register it with this key. also i tried to ad new software at my online adobe.com account, with this serial, and it said "already registered" but it wont show up in my account. Whats wrong here?
Will send the serial/key if needed by pn.
Greetings
ImmschaIs the key you’re trying to use for the same version of PSE that you have installed on your laptop, i.e. 10, 11, 12?
Do you see anything on your Adobe account for registered software? Be aware that the page takes some seconds or 10s of seconds to populate with your products so will look empty for a while. This is the page I'm talking about:
https://www.adobe.com/account/my-products-services.html -
How to get the opening balances for lessthan selected date in cubes.
Hi All,
my task is to get the opening balances for the selected date.
Ex: If I select date say 31-1-2013, I should get the sum of values which are less than the selected date.
in sql:
select sum(balance) from banktrans where banktrans.transdate < 31-1-2013;
BankTable BankTrans
BankId BankId
balance
transdate
BankTable (records):
SCB
BankTrans(records):
a) SCB, 15000, 10-02-2013
b) SCB, 20000, 31-01-2014
c) SCB, 50000, 21-09-2012
If I select date as 31-01-2014, I should get the value as 65000
If I select date as 10-02-2013, I should get the value as 50000
Date will be dynamic selection from years months days hirearchy ( time dimension)
How can i achieve this?
any help is much appreciated.
Thanks,
RakeshDear David,
I've tried the below with static date but i'm not getting the values which are sum of less than the given date.
I've given 1st jan 2013 as static date and I need to get the sum of values which are less than the 1st jan date.
CREATE
MEMBER
CURRENTCUBE.[Measures].[OPENBALANCE]
AS
Sum({Null:[Time].[Years
Quarters Months Weeks Days].[Days].&[2013-01-01T00:00:00]},[Measures].[AmountCur]]),
FORMAT_STRING
= "Standard",
VISIBLE
= 1
can you plz check the above once and guide me.
Thankyou,
Rakesh -
ABAP Get Week Number for a Given Date.
Hi All,
I want to calculate week number for given date.
SAP has provided function modules like DATE_GET_WEEK.. Etc are giving week number. taking default start day as Monday. But for my requirement is calculate week number based on start day as Sunday.
Please let me know if we have any custom logic ??
Thanks & Regards
Vasu YadavHi Vasu,
SAP standard functionality takes MONDAY as first day.
But if you want then you can change it to SUNDAY by implementing BADI CALENDAR_DEFINITION. Create a new implementation for method IF_CALENDAR_DEFINITION~GET_FIRST_DAY_OF_WEEK and assign value as SUNDAY.
Hope it solves your problem.
Thanks
Saurabh Kabra -
How to get the serial number for the UUT in Test 5.0 version?
The "RunState.Caller.Locals.UUT.SerialNumber" reference does not for the newer version of TestStand. What would be another method to get the UUT serial number for the batch?
Please help. Thanks.RunState.Caller.Locals.UUT.SerialNumber only works in certain locations, specifically when Runstate.Caller is Runstate.Root.
Use RunState.Root.Locals.UUT.SerialNumber. -
How to get the weekends days for a specific date range
I want to select list of only weekend dates from a given date range. Is it possible in SQL?
For example if the range is '08/01/2011' and '08/30/2011'
I want a list
08/06/2011
08/07/2011
08/13/2011
08/14/2011
08/20/2011
08/21/2011
08/27/2011
08/28/2011Thank You, Naveen email:[email protected]First and easy to do is having a Calendar table, which over there you can have those information.
http://arbibaghdanian.blogspot.com/2011/05/calendar-table.html
Declare @beginDate Date, @EndDate Date
Select @beginDate = '08/01/2011', @EndDate = '08/31/2011'
Declare @Calendar Table
(CalendarDate Date Primary key, IsWeekend Bit, YearNo SmallInt, QuarterNo TinyInt, MonthNo TinyInt, DayOfYearNo SmallInt, DayNo TinyInt, WeekNo TinyInt, WeekDayNo TinyInt)
While @beginDate <= @endDate
Begin
Insert Into @Calendar
Select
@beginDate As CalendarDate
,(Case When DATEPART(Weekday, @beginDate) In (7, 1) Then 1 Else 0 End) As IsWeekend
,DATEPART(Year, @beginDate) As YearNo
,DATEPART(QUARTER, @beginDate) As QuarterNo
,DATEPART(MONTH, @beginDate) As MonthNo
,DATEPART(DayOfYear, @beginDate) As DayOfYearNo
,DATEPART(Day, @beginDate) As DayNo
,DATEPART(Week, @beginDate) As WeekNo
,DATEPART(WEEKDAY, @beginDate) As WeekDayNo
Set @beginDate = DateAdd(Day, 1, @beginDate)
End
Select * From @Calendar Where IsWeekend = 1
Best Wishes, Arbi --- MCC 2011; Please vote if you find this posting was helpful or Mark it as answered. -
How to get/view document number for KP06 Planning upload
Hi,
I have uploaded excel for Cost center/cost element Planning in KP06 using exccel planning.Now i want the document number which for which i have posted in KP06-Plan values using excel upload.
Kindly advice me how to get the document number for CO-OM(Cost center/Cost element planning) in KP06?
Thanks
SupriyaHello,
Please execute report KSBL. It should be useful.
Regards,
Ravi -
I recently subscribed to Acrobat XI after the trial expired but when I went to activate it I was asked for the serial number. I only have the order number on the invoice. How do I get the serial number for the trial software that is on my computer?
Please do not try to send attachments in mail responses to forum messages. Please return to the forum and click Reply. You can then use the CAMERA icon to add your pictures. Looking forward to seeing what is wrong with your license screens - the general advice is simply to sign in, and everything is done. Make sure you use the SAME Adobe ID that you used to purchase, and check your account details to be sure the subscription is active.
-
How can I get the serial number for Premiere 11?
In october 2012 I´ve bought a bundle pack with Photoshop Elements 11 and Premiere 11. After a hard disk crash i was about to reinstall them both but my wife has trown the envelope in the garbage... = No Serial number available!!
I´ve registered the serial number for Photoshop Element 11 on Adobe, but not the key for Premiere (they are on the same dvd).
How can I get the serial number for Premiere 11?I do not think there is any way for anyone here to help you (we are just other users) so you are going to have to contact Adobe
Forum for Download & Install & Setup problems
http://forums.adobe.com/community/download_install_setup
Chat http://www.adobe.com/support/download-install/supportinfo/
-or http://www.adobe.com/support/chat/ivrchat.html
And tell your wife to be more careful about throwing things away
Maybe you are looking for
-
Dragging files from a mac to a pc
Hi there I've set up file sharing on the macs to allow windows samba file sharing. When I browse to the mac hard drive from my pc I can see all the accounts in Users and the folders. I can open them all e.t.c If I try to drag a folder from the mac to
-
How do I restore playlist without corrupting/dupping library?
I have a large music collection (50k+) titles which I gathered while deployed. After several transfers/backups among external/internal harddrives, updates of iTunes and the use of Homesharing, the library became a mess of duplicates growing to over
-
Data in first tab also shown in second tab
I'm using Java Swing. I have a tab panel with 2 tabs. In the first tab, I entered data. I want the data to show on the Combo Box in the second tab without closing the tab panel and open it again. How can I refresh the second tab with the newly added
-
Adobe Reader 11.0.03 crashes every time I open a PDF. I see the grey box saying Reading Untagged Document then it crashes with the message that Acrobat is not responding. I have Windows 7 Professional. I have tried uninstalling and re-installing s
-
Times change, moderators come and go. Here is some advice from an old timer to any new moderators, and those that may desire to be one in the future. I was never an official full fledged moderator here at this forum or at others. Be that as it may, t