How to get week of a year in American Standard
Hi,
I know it might be a repetitive question, but did not find a convincing solution to it in any of the previous threads. I am looking for a function (user defined, if someone has already written it) to return me the week of the year, in American Standard. i.e,the week should start on Sunday and end on Saturday (and NOT from Monday to Sunday)
01/03/2010 - Should be the start of 1st week of 2010...... 01/10/2010 will be the start of second week and so on
01/04/2009 - Should be the start of 1st week of 2009...... 01/11/2009 will be the start of second week and so on.
Does any one have a function that takes a date as input and returns back the week of the year in this above format? Any help is greatly appreciated.
Thanks
It's a bit trickier because the ISO rule has some fine prints.
Take a look at the example below:
SQL> with t as (
2 select to_date('01/02/2010', 'MM/DD/YYYY') dt from dual union all
3 select to_date('01/03/2010', 'MM/DD/YYYY') dt from dual union all
4 select to_date('01/03/2009', 'MM/DD/YYYY') dt from dual union all
5 select to_date('01/04/2009', 'MM/DD/YYYY') from dual)
6 --
7 select dt,
8 to_char(dt+1, 'iw') tweaked_week,
9 to_char(dt, 'ww') nls_week
10 from t
11 order by dt;
DT TWEAKED_WEEK NLS_WEEK
3/1/2009 01 01
4/1/2009 02 01
2/1/2010 53 01
3/1/2010 01 01
SQL> If may notice that 02/01/2010 is week 53 and and that at the same time 03/01/2009 is already week 1, being 04/01/2009 week 2.
The reason is in the docs:
An ISO week always starts on a Monday and ends on a Sunday.
* If January 1 falls on a Friday, Saturday, or Sunday, then the ISO week that includes January 1 is the last week of the previous year, because most of the days in the week belong to the previous year.
* If January 1 falls on a Monday, Tuesday, Wednesday, or Thursday, then the ISO week is the first week of the new year, because most of the days in the week belong to the new year.It depends on what your requirement asks.
If you need to prevent any January 1st that fall on Monday to Thursday from becoming your week 1 you'd probably have to adjust that implementation and fine tune it further.
Let us know if that will do or what your rule would be otherwise.
Similar Messages
-
How to get Week,Month and Year details from a date column
Hi frenz,
I've a column like tran_date which is a date column..... I need the next week details based on this column and so on...
I need month and year details as well based on this tran_date column.... can any one tell me how...
Thanks in advanceMy example for objects:
create or replace type date_object as object
centure number,
year number,
month number,
day number,
hour number,
minute number,
second number,
daypart number,
week number,
constructor function date_object(p_dt date)
return SELF as result
create or replace type body date_object is
constructor function date_object(p_dt date)
return SELF as result
as
begin
SELF.centure:= trunc(to_char(p_dt,'YYYY')/100);
SELF.year:= to_char(p_dt,'YYYY');
SELF.month:= to_char(p_dt,'MM');
SELF.day:= to_char(p_dt,'DD');
SELF.hour:= to_char(p_dt,'HH24');
SELF.minute:= to_char(p_dt,'MI');
SELF.second:= to_char(p_dt,'SS');
SELF.daypart:= p_dt-trunc(p_dt,'DD');
SELF.week:= to_char(p_dt,'IW');
return;
end;
end;
select date_object(sysdate),
date_object(sysdate).year
from dual;Regards,
Sayan M. -
How to get and display current year
hi,
how to get and display current year
and need it to convert numeric format if it is orginally
in character format.Hi,
chk this FM.
CALL FUNCTION 'GET_CURRENT_YEAR'
EXPORTING
BUKRS = '1000' " Company Code
DATE = SY-DATUM " Date to find fiscal year for
IMPORTING
CURRM = w_currm " Current Fiscal Month
CURRY = w_curry " Current Fiscal Year
PREVM = w_prevm " Previous Fiscal Month
PREVY = w_prevy. " Previous Fiscal Year
rgds
anver
if hlped pls mark points -
How to get the transport request for a particular standard text?
Hi,
i want to know, how we get the transport request which associated for standard text.
Please note already the standard text is assigned to the TR using RSTXTRAN program.
i have a std text. i want to find the related TR for that!
rds,
Siva.Refer the link. It might tellsa about attaching to transport request but using the way you can find also -
Re: How To Transport STANDARD TEXTS??
Regards,
Amit
Reward all helpful replies -
How to get week number and day in my result?
hi experts, i have given the data is ID and DATE(yyyymmdd),i want to get output like ID,DATE,WEEKNO,YEAR,MONTH,DAY. how to get this output.
thanks & regards
vijayIn a routine transformation you can call function
DATE_GET_WEEK
to get the week number from the date.
To determ the others, use the substring
YEAR = DATE(4)
MONTH = DATE+4(2)
DAY = DATE+6(2) -
How to get week number from date
Hi,
please mention how to get the number of week from a particular date using fn module?Hi Debarshi,
Use FM <b>DATE_GET_WEEK</b>
Reward points if helpful.
Regards,
Hemant -
How to get the number of years, months with two sysdate()
Hi All,
Sorry for posted another question regarding the conversion.
I have the hiring day and current day in date format like : '2005-10-01' and '2006-09-14'
How to get the differences between current date is ('2006-09-01') and
hiring date is ('2004-10-01' )
in the format number of years and number of month without using the Mod
function . For this example the result is : 2 years 1 month
Thanks
JPHow to get the differences between current date is ('2006-09-01') and
hiring date is ('2004-10-01' )
in the format number of years and number of month without using the Mod
function . For this example the result is : 2 years 1 monthshould not it be 1 year 11 months???
SQL> select (date '2006-09-01' - date '2004-10-01') year to month diff from dual;
DIFF
+01-11 -
How to get consolidated last financial year(1-July-2011 onwards) Tablesize
Hi All,
My database contain 120 tables.
Could you please suggest me the consolidated last financial year (1-July-2011 onwards) data size for 120 tables shared before?
How to get this/Is this possible Please advice.
I used below query, but date wise..how to do. pls suggest.
SELECT sum(BYTES)/1024/1024/1024 "SIZE IN GB" FROM DBA_SEGMENTS WHERE SEGMENT_NAME IN(Table1,table2…)
Regrads,
VenkatIf the data is not partitioned, it is not easy to get the exact size, and it might be impossible.
I can see two approaches.
- use the vsize function to calculate the size of a row, and/or individual columns (I don't recall whether vsize supports the *)
set up an appropriate where clause
- get the avg_row_size from user_tables. Count the number of rows by year. Multiply.
Sybrand Bakker
Senior Oracle DBA -
How to get week starting with sunday date
Hi
I have a date column "start_date", i need to create a report for all the weeks starting from sunday , for eg:
i need to get week dates as :
mm/dd/yy - 01/23/11 , 01/16/11 , 01/09/11 and so on...
Please help
Thanks...Hi,
To find the last Sunday before or equal to start_date:
SELECT TRUNC ( start_date + 1
, 'IW'
) - 1 AS week_start_date
...You can use an expression like this in a GROUP BY clause, also.
This does not depend on you NLS settings. ISO weeks always start on Monday. Your week starts 1 day earlier, so that's why the expression above has the +1 and -1.
(Depending on you NLS settings,
SELECT TRUNC ( start_date
, 'D'
) AS week_start_date
...might do the same thing, but I still rocommend using 'IW'; a few extra keystrokes isn;t much to pay for a guarantee that it will always work.)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. -
How to get Current month last year sale in report
HI,
I would like to compare the sale value of a month for any year.
ie sale of the march month for this year ,previous year and a year before ..like that
at least for two years..ie current and prvious year.
how can i get it done in query?
thnxCreate three restricted key figures.
In one restrict month by current month.
In other use offset of -12 and -24 while restricting current month. -
HT2513 how do get to view the year in ical?
I have ical on my MacOsX version 10.6.8. New at using ical, however I'm wanting to view the year and it will only let me view, day,week,month! help???
Possibly,
Looking at iCal version 4, open iCal Help, and after being connected to the server, you will see 'Inviting Guests to an event'. Click on that for information, and also at the bottom of that window in Related topics, is the topic, 'Setting your email address so you can send or modify your event invitations'. That link may also be useful. -
How to get my photo moments/years to an external hard drive or dropbox
Hello! I'm stuck. I apologize if my technical lingo is wrong. I'm trying to keep my head above water in understanding my predicament. Our home was broken into while away before Christmas, and my 2009 Macbook Pro and new external hard drive were stolen. Luckily I had just purchased a new Macbook Pro (it says here its OS X Yosemite Version 10.10.1 2.6 GHz 8 GB 1600 MHz DDR3) and did I migration assistant on it prior to leaving. However all the photos and files from my old Macbook wouldn't fit on the new one. So I brought over files but not photos. I then backed up the old mac onto an external hard drive (which was later stolen). While away we kept getting a warning that we were out of start up space. So on the prompting of my husband that we don't need all our files on the computer and they should be stored back at home anyways we started deleting files to make room to download some of our travel photos.
When we got to home to find our home ransacked and computer and back up hard drive gone, I then realized most of the files left on the new mac that I hadn't deleted, which were brought over via migration assistant won't open. One computer guy told me that they are corrupted and without the original backed up hard drive there's no saving them.
So then I moved on to trying to move what files I have left onto drop box so that perhaps I could go back in time machine and get my files that we deleted while away. But now drop box says I don't have permission to move all the files, and has only moved new documents I've made since working on the new mac.
I do potentially have the option of trying to go back 28 days in my Time machine to before I deleted the files to make room on our trip, but one computer guy told me if I try this, it most likely will ask for the original back up hard drive. And I could risk loosing what I do have.
BIGGEST concern to me is all our family photos. Magically (and I say this thankfully!) I can still see all of our photos in the "Moments/Years" on my iPhone 5. However when I try to download them into iPhoto. It will only download the resent photos that have been taken in the camera roll. I really really hope some very clever angel has figured out a way to get all these photos from Moments and into dropbox. I should mention that I did try turning on iCloud today, but I get a warning that says "Photos synced from iTunes will be removed. Syncing photos via iTunes is not supported when iCloud photo library is turned on. 6,818 photos will be removed.
So really I'm at a loss of what to do next. And scared to try anything myself that may make matters worse. Most the computer techs I've talked to so far seem as dazed as I am about a solution. Any help will be greatly appreciated! Thank you!chevalierdurufle wrote:
My itunes library used to be on a PC - but shortly before the PC went to PC heaven I transferred the library onto an external hard drive
You mean you transferred the media, not the library...
Now I have a laptop - but I can't get itunes to pick up the library location
The library location is in your /Music/ oflder.
Your media files (not yet in your new iTunes library ) is on the external drive.
I have changed in advance preferences, but the library does not display.
Because you have not yet added anything to your library.
Quit iTunes.
On the external, create a new folder named My iTunes library (or something).
Hold Shift and launch iTunes.
Select Choose library... and select My iTunes library on the external.
Go into Windows Explorer and move all the media files on the external into /My iTunes Llibrary/iTunes media/Automatically add to iTunes/ folder. -
How to get the 4 digits year from 2 digits
Hi ,
I have a column which stores the last two digits of the year like 08,09,10 etc.. Now I need to get the complete year number from these two digits. Is there any function in oracle which will help this purpose.
Thanks,Hi,
user8640661 wrote:
Hi ,
I have a column which stores the last two digits of the year like 08,09,10 etc.. Now I need to get the complete year number from these two digits. Is there any function in oracle which will help this purpose.
Thanks,What are the other two digits?
If they're always '20', then concatenate '20' to your existing column (which I assume is a string):
'20' || a_columnIf the first 2 digits are '20' when the existing sting is in the range '00' to '49', but '19' when the existing string is in the range '50' to '99', then use the 'RR' date format:
TO_CHAR ( TO_DATE (a_column, 'RR')
, 'YYYY'
)but hurry; this will behave differently starting in 2050.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. -
How to get week nos for a month ?
hi frends...
i ve a requirement i ve to display week nos available in a month....
for e.g.,
this is my input month = 0908 that is (september 2008)
and i ve to get output as
36
37
38
39 ....these are all week noshi ,
make use of the following code for your requirment.
FUNCTION ZZTEST1.
""Local Interface:
*" IMPORTING
*" REFERENCE(I_DATE) TYPE CHAR4 OPTIONAL
*" EXPORTING
*" REFERENCE(EX_WEEK1) TYPE CHAR2
*" REFERENCE(EX_WEEKUPTO) TYPE CHAR2
data : lv_date1 type sy-datum,
lv_date2 type sy-datum,
lv_week1 type scal-week,
lv_week2 type scal-week,
lv_mon type sy-datum,
lv_sun type sy-datum,
lv_enddt type S033-SPTAG.
Data : lv_mm(2) type c,
lv_yy(2) type c,
lv_dd(2) type c.
lv_mm = i_date(2).
lv_yy = i_date+2(2).
lv_dd = '01'.
concatenate '20' lv_yy lv_mm lv_dd into lv_date1.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = lv_date1
IMPORTING
WEEK = lv_Week1
EXCEPTIONS
DATE_INVALID = 1
OTHERS = 2.
ex_week1 = lv_week1+4(2).
CALL FUNCTION 'CBIH_RP02_GET_END_MONTH'
EXPORTING
DATE_MONTH = lv_date1
IMPORTING
END_MONTH = lv_enddt.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = lv_enddt
IMPORTING
WEEK = lv_Week2
EXCEPTIONS
DATE_INVALID = 1
OTHERS = 2.
ex_weekupto = lv_week2+4(2).
ENDFUNCTION. -
How to get week of the current month
Hi all,
Is there any way to find out week of the current month.
Please help..Do not confuse date format and the parameter in the file NqsConfig.ini
http://gerardnico.com/wiki/dat/obiee/bi_server/nqsconfig
As say in the previous link, you must check in the NqsCOnfig.ini file that you have this line
DATE_TIME_DISPLAY_FORMAT = "yyyy/mm/dd hh:mi:ss" ;because the cast function take it as format to discover the day, month and year.
Besides, the functions WEEK_OF_YEAR AND MONTH don't care about the date format, they only need a date.
Check here this article :
http://gerardnico.com/wiki/ide/toad/toad_date_format
To see that the date format is much more a question of rendering (for OBIEE, Toad or SqlPlus) than of data.
Verify your NqsConfig.ini and give a try.
Success
Nico
Maybe you are looking for
-
Can i use classes or grid control (alv) in normal report
Hai, Can i use Grid control or classes in normal report.If yes what are the steps that i have to go for. thanks kiran
-
Apple TV no longer plays iPhoto slideshows (individually)
I have been using AppleTV for a couple of years, primarily to play iPhoto slideshows to music on our TV's. With a recent update (either to Apple TV, iTines or iPhoto, not sure, but I think it changed after an Apple TV update) we can no longer watch o
-
How can I stop sync and remove a computer from my iphone?
How can I Cancel iphone wifi sync with my computer? and how do I remove my computer (W-VAIO) from my list? I did the settings from iTunes & it still doesn't work, I even hit the 'apply' button..... what do I do? I recently plugged a friend's phone on
-
Unable to connect to Mac Pro with 2 network interfaces
The Mac Pro has 2 network interfaces. The first one is connected to a local network and the other interface has an external IP address (connected directly to the internet). What we want to be able to do is to connect to the computer from home through
-
Events disappearing from Outlook Calendar when synced with iPhone 4
Hi, I have just switched from iPhone 4 to iPhone 4S. I have the same iTunes and Apple ID on both the iPhones (the other one is used by my wife) but I created different iCloud ID for both the iPhones. When I synced the new iPhone 4S with my laptop, I