Find date if year, month, week and day is given

Hi,
How to find the date, if year, month, week and day is given?
For example:
Given, year - 2010, month - 03, Day - Wednesday, Week - 3,
Then how can we get the date as 17-Mar-2010.
Thanks,
Chris

with dt_tbl as (
                select  2010 year,
                        3 month,
                        3 week,
                        'Wednesday' day
                  from  dual
select  trunc(to_date(year || '-' || month || '-01','yyyy-mm-dd'),'iw') + (week - 1) * 7 +
          case day
            when 'Monday' then 0
            when 'Tuesday' then 1
            when 'Wednesday' then 2
            when 'Thursady' then 3
            when 'Friday' then 4
            when 'Saturday' then 5
            when 'Sunday' then 6
          end dt
  from  dt_tbl
DT
17-MAR-10
SQL> SY.

Similar Messages

  • Get number of month, week and date between 2 dates

    Hi all,
    Is it possible to display number of month, week and days between 2 dates? either by using only SQL query or through PL/SQL...
    Input:
    From date: 01-Oct-2010
    To date: 19-Oct-2010
    I want output as below (Assuming the week starts from Monday to Sunday in oracle).
    01-Oct-2010 -- (Since this is in mid of the week)
    02-Oct-2010 -- (Since this is in mid of the week)
    03-Oct-2010 -- (Since this is in mid of the week)
    40 -- (Oct 4 to Oct 10 falls in 40th week of the year)
    41 -- (Oct 11 to Oct 17 falls in 41th week of the year)
    18-Oct-2010 -- (Since this is in mid of the week)
    19-Oct-2010 -- (Since this is in mid of the week)
    Note: If there is one full month between the given date, then the month number should be displayed.
    After the month, the remaining date comprised with one full week, then the week number of the year should
    be displayed. After displaying the week, the remaining dates should be displayed as it is..
    Appreciate your help..
    Thanks.
    Rajan.

    I suppose if it's just like a calendar type information you want then something like...
    SQL> break on month skip 1
    SQL> set linesize 200
    SQL> set pagesize 2000
    SQL> column month format a20
    SQL> column week format a4
    SQL> with req as (select '&Required_Year_YYYY' as yr from dual)
      2      ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req
      3  select lpad( Month, 20-(20-length(month))/2 ) month,
      4         '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
      5  from (
      6    select to_char(dt,'fmMonth YYYY') month,
      7    case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
      8         when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
      9         when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    10         else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
    11    max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Mo",
    12    max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Tu",
    13    max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "We",
    14    max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "Th",
    15    max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Fr",
    16    max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Sa",
    17    max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Su"
    18    from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
    19           from all_objects, req
    20           where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
    21        ,offset
    22    group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
    23                                                  when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
    24                                                  when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    25                                                  else to_char(to_number(to_char(dt,'iw'))+offset) end
    26    ) x
    27  order by to_date( month, 'Month YYYY' ), to_number(x.week)
    28  /
    Enter value for required_year_yyyy: 2010
    old   1: with req as (select '&Required_Year_YYYY' as yr from dual)
    new   1: with req as (select '2010' as yr from dual)
    MONTH                WEEK Mo Tu We Th Fr Sa Su
        January 2010     (1)               1  2  3
                         (2)   4  5  6  7  8  9 10
                         (3)  11 12 13 14 15 16 17
                         (4)  18 19 20 21 22 23 24
                         (5)  25 26 27 28 29 30 31
       February 2010     (6)   1  2  3  4  5  6  7
                         (7)   8  9 10 11 12 13 14
                         (8)  15 16 17 18 19 20 21
                         (9)  22 23 24 25 26 27 28
         March 2010      (10)  1  2  3  4  5  6  7
                         (11)  8  9 10 11 12 13 14
                         (12) 15 16 17 18 19 20 21
                         (13) 22 23 24 25 26 27 28
                         (14) 29 30 31
         April 2010      (14)           1  2  3  4
                         (15)  5  6  7  8  9 10 11
                         (16) 12 13 14 15 16 17 18
                         (17) 19 20 21 22 23 24 25
                         (18) 26 27 28 29 30
          May 2010       (18)                 1  2
                         (19)  3  4  5  6  7  8  9
                         (20) 10 11 12 13 14 15 16
                         (21) 17 18 19 20 21 22 23
                         (22) 24 25 26 27 28 29 30
                         (23) 31
         June 2010       (23)     1  2  3  4  5  6
                         (24)  7  8  9 10 11 12 13
                         (25) 14 15 16 17 18 19 20
                         (26) 21 22 23 24 25 26 27
                         (27) 28 29 30
         July 2010       (27)           1  2  3  4
                         (28)  5  6  7  8  9 10 11
                         (29) 12 13 14 15 16 17 18
                         (30) 19 20 21 22 23 24 25
                         (31) 26 27 28 29 30 31
        August 2010      (31)                    1
                         (32)  2  3  4  5  6  7  8
                         (33)  9 10 11 12 13 14 15
                         (34) 16 17 18 19 20 21 22
                         (35) 23 24 25 26 27 28 29
                         (36) 30 31
       September 2010    (36)        1  2  3  4  5
                         (37)  6  7  8  9 10 11 12
                         (38) 13 14 15 16 17 18 19
                         (39) 20 21 22 23 24 25 26
                         (40) 27 28 29 30
        October 2010     (40)              1  2  3
                         (41)  4  5  6  7  8  9 10
                         (42) 11 12 13 14 15 16 17
                         (43) 18 19 20 21 22 23 24
                         (44) 25 26 27 28 29 30 31
       November 2010     (45)  1  2  3  4  5  6  7
                         (46)  8  9 10 11 12 13 14
                         (47) 15 16 17 18 19 20 21
                         (48) 22 23 24 25 26 27 28
                         (49) 29 30
       December 2010     (49)        1  2  3  4  5
                         (50)  6  7  8  9 10 11 12
                         (51) 13 14 15 16 17 18 19
                         (52) 20 21 22 23 24 25 26
                         (53) 27 28 29 30 31
    61 rows selected.
    SQL>

  • Creating Hierarchy Year-Month-Week-Dayof Week.

    Hi,
    We have a requirement to create new HR report - Labour Efficiency.
    We require 'Date of work' in BI report.
    It takes value from CATSDB table, WORKDATE field in R/3. Its Data Type- DATS , Integer length 16, output length 10.
    But in BI report they want hierarchy Year-Month-Week-Dayof Week  for this 'Date of work' field.
    How this can be achieved?
    Edited by: Amruta_Kedar on Sep 6, 2011 8:18 AM

    Hi Dilek,
    I have checked out the link and procedure given.
    I have never used this option neither any of the time hierachie is active in our system. Could you please elaborate how we used these hierarchies in BEx?
    I am confused which hierachy is to be selcted here. I didnt find any hierarchy Year-Month-Week-Dayof Week.
    Also, where do we activete these hierarchies (R/3 or BI side) ?
    Another question : 'Date of work' infoobject should be a characteristic of type DATS or a key figure of type DATE??
    which option will be better to do this kind of analyis on date?

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

  • My Month view says July, but my Week and Day views say January

    There appears to be a glitch in my iCal. Thanks to these discussions, I finally got it to accept 24 hour clock input (though it still displays times as 12 clock until I go in to check), but I am flummoxed by the fact that only in the Month view do I see the correct month. In Week and Day views it is always January. How can I correct the Week and Day views? By the way, I can't believe I am the only one to write about this. I searched but couldn't find any similar questions.

    racjstevens,
    Welcome to Apple Discussions.
    Try changing your default paper size in System Preferences...>Print & Fax>Printing.
    Is there any reason that you are still using 10.4.1? The current system is 10.4.10.
    Also check this search for other suggestions.
    ;~)

  • Default selection on current month, week and date

    Hi,
    We are on Dashboard 4.1 sp3 the same version as BI.
    The dashboard report is using LiveOffice connection. We are now facing an issue with default selection on current month, week and date.
    The dashboard report drilled down from month, to week, then to date. The dashboard feed -live office report is on month/week/date ascending order - becuase we have running average calcualtion on LO report, it seems have to be in ascending order to get the correnct runnning average.
    I tried to on Insertion to change default seletion, it works on month, but it doesnt working on week and daily.
    but when LO report is on ascending order, on dashboard column chart the default selection is not on the current month, week and date.
    Is there a way to solve the issue. Could anyone please help.
    Thanks,

    Hi Suman,
    Thanks for the quick reply.
    Do you mean I Enable sorting -by categrory labels on Behaviour - common tab.
    Thanks,

  • Year-month-week selection screen format?

    Hi experts,
    I will create sd report but I need selection screen that includes year-month-week,
    example;
    Year   :   2012
    Month :  March    ( Listbox for all months )
    Week :  1.week   
    I wıll execute report like that.
    This report program is going to be comparison of weeks in specific years.
    How can I achieve this selection screen ?
    any help will be appreciate
    best regards

    Hello Kutay,
    This is an example of listbox.
    PARAMETERS:  listbox(1) AS LISTBOX VISIBLE LENGTH 10 DEFAULT 'N'.
    AT SELECTION-SCREEN OUTPUT.
    DATA:
    name TYPE vrm_id,
    list TYPE vrm_values,
    value TYPE vrm_value.
    name = 'LISTBOX'. " Name should be in UPPER CASE
    value-key = '1'.
    value-text = 'January'.
    APPEND value TO list.
    value-key = '2'.
    value-text = 'February'.
    APPEND value TO list.
    CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
    id = name
    values = list
    EXCEPTIONS
    id_illegal_name = 0
    OTHERS = 0.
    Idem for week field.
    I hope you help.

  • InfoObject that stores "Yearly/Monthly/Weekly/Daily"

    Hi,
    I'm looking for a standard object that stores values Yearly/Monthly/Weekly/Daily etc.
    It could also be Year / Month / Week etc...
    Do you know of such an Standard Content InfoObject?
    Thanks in Advance
    Rudolph

    Calendar Year                    0CALYEAR
    Calendar Year/Month          0CALMONTH
    Calendar Year/Week           0CALWEEK 
    Calendar day                      0CALDAY
    Calendar month                  0CALMONTH2
    Calendar year/quarter          0CALQUARTER
    Fiscal year                         0FISCYEAR
    Fiscal year / period             0FISCPER 
    Fiscal year variant               0FISCVARNT
    Halfyear                              0HALFYEAR1 
    Posting period                    0FISCPER3
    Quarter                             0CALQUART1
    Weekday                          0WEEKDAY1
    Hope this helps......

  • Ical displays Wednesday every day in Week and day view

    Upgraded to SnowLeopard and added "calendar.app" from the app store, evr since ical displays "Wednesday" everyday in week and day views. Any ideas?

    Replying to myself as this may help others!
    The problem was in system preferences. It was set to custom!!

  • Add dynamic parameters for Year, From Week and To Week.

    hi all,
    my requirement is Add dynamic parameters for Year, From Week and To Week.
    can any one help how to do this one plz....
    in Answers..
    advanced Thanks..

    hi kansal,
    These requirement for the BI Publisher reports,
    1)Add dynamic parameter for year, From week and To week.
    2) Year to default to Current Year.
    that's what i have dude..
    may be we need to assign the dynamic variables for year ..
    Edited by: 932326 on Sep 4, 2012 7:16 AM

  • Hello i lost my ipod touch 5g and I can not find I lost 8 months ago and i try

    hello i lost my ipod touch 5g and i can not find i lost 8 months ago and i try to find whith  find my iphone I need help please

    See my response to your other post

  • My iPod was stolen a long a few months ago and I've given up all hope in finding it. I have never purchased item on iTunes, and I think the iCloud might have been deleted. It doesn't show up in "My products" either.

    My iPod was stolen a long a few months ago and I've given up all hope in finding it. I have never purchased item on iTunes, and I think the iCloud might have been deleted. It doesn't show up in "My products" too and I tried Find My iPhone.

    No. Apple won't do anything without a court order. Since it wasn't upgraded to iOS 7 before it was stolen then there's nothing you can do. You could file a police report with your serial number but there may be a small chance.

  • Date separate year, month and day

    Hello everyone and thanks in advance, I'm new to this and the truth is not doing this.
    Well, I have a PDF with several pages which I designed and has been asking me in a complete date in the format dd / mm / yy and subsequent pages he asks me the same date of birth but in 3 separate fields, day , month and year. I want you when you enter the date the first copy and separate day month and year in others. I tried this but I get
    var array_datesol = datesol.split("/")
    var year = parseInt(array_datesol[2]);
    var month = parseInt(array_datesoll[1]);
    var day = parseInt(array_datesol[0]);
    this.getField('yearsol').value = year;
    this.getField('monthsol').value = month;
    this.getField('daysol').value = day;
    where is the initial field datesol date and year, month and day where they have to be separately
    thanks in advance

    Are you getting any errors in the JavaScript debugging console?
    You are using the syntax for the 'Custom JavaScript calculation' and this syntax can not be used in the 'simplified field notation. Also you can not use any JavaScript properties, objects, functions, control statments.
    When run in the console, I find you have a misspelling of the variable name 'datesol'. I also do not see where you are initializing the value for 'datesol'.
    var datesol = event.valueAsString;  // get value of this field
    var array_datesol = datesol.split("/") ; // make into an array
    this.getField('yearsol').value =array_datesol[2];  // get element year
    this.getField('monthsol').value = array_datesol[1];  // get month element - fixed variable name
    this.getField('daysol').value = array_datesol[0]; // get date element
    I would use one of the following so the other fields are only updated when a date has been entered and the leading zeros are displayed:
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.value != '') {
    // get parts of date and print with leading zeros
    var datesol = event.value;  // get value of this field
    var array_datesol = datesol.split('/') ; // make into an array
    this.getField('yearsol').value = util.printf('%,304.0f', array_datesol[2]);  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', array_datesol[1]);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', array_datesol[0]); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if (event.value != '') {
    // get date parts and print with leading zeros
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printf('%,302.0f',oDatesol.getFullYear());  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', oDatesol.getMonth() + 1);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', oDatesol.getDate()); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.vaue != '') {
    // get parts of date and format
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printd('yyyy', oDatesol); // get element year
    this.getField('monthsol').value = util.printd('mm', oDatesol); // get month element - fixed variable name
    this.getField('daysol').value = util.printd('dd', oDatesol); // get date element
    If you are going to fill other field, you will need to use the '.valueAsStriing' property or '.toString()'  method to retain the leading zeros.

  • Extract Year/Month/ Week From Date

    BW Experts,
      I have a Time Char in a New OSD i am developing. Say the Time char is 0Req_date. This 0req_date is updated using some calculation in my update rules (Say 0Req_Date = Act_dl_dt - Conf_date). Now I have to extract month/ year/ week and populate Time Chars 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK respectively from 0REQ_DATE. Can I do this via respective rules to 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK in the update rules. My concern is as OREQ_DATE itself is a calculated field, can month/year/week be extracted correctly? Hope I have put the question across understandably. Help is appreciated.
    Thanks
    Ashwin

    Hi Ashwin,
    It can be done...you can either put the code for all these derivations in the Start Routine of the update rule, making sure that the 0REQ_Date is calculated before the others. Or you can also calculate just the 0REQ_DATE in the start routine and use the individual update routines to populate the other time chars.
    Processing using the Start Routine is recommended for efficiency and better performance.
    Hope this helps...

  • Calculation based on date but year&month on seperate fileds.

    Hello,
    Simple question:
    I have a table in 9i with the fields SOURCE, YEAR, MONTH
    Since I dont have a date field, how do I count e.g the records <07/2008 ?
    SAMPLE DATA:
    APPLES;2008;06
    APPLES;2008;07
    APPLES;2008;08
    Thank you in advance for your help.

    Without conversion to date:
    WITH sample_data AS (SELECT 'APPLES' Source, '2008' AS Year, '06' AS Month
                           FROM DUAL
                         UNION ALL
                         SELECT 'APPLES', '2008', '07'
                           FROM DUAL
                         UNION ALL
                         SELECT 'APPLES', '2008', '08'
                           FROM DUAL)
    SELECT *
      FROM sample_data
    WHERE YEAR < '2008' OR (YEAR = '2008' AND MONTH < '07');The "WITH sample_data AS (...)" block serves to mimic a sample table, so you can SELECT COUNT(*) FROM SOURCES
    WHERE YEAR < '2008' OR (YEAR = '2008' AND MONTH < '07');Urs
    Edited by: metzguar on 30.06.2011 13:15

Maybe you are looking for

  • Upload fields from SAP R/3 to BW

    Dear All, I'm looking for a method to upload fields from SAP R/3 to BI 7.0. My testing case as following: - Upload table DFKKKO \ field OBEL from R/3 to BW - I created a Generic Datasource and select this field. - When coming back to BI, I replicate

  • MobileMe Calendar won't load on OS X 10.7.2

    I try to add MobileMe calendar to iCal on OSX 10.7.2 and I get the message "iCal couldn't log in to the CalDAV server "me.com".  Standard apply reply in support is to upgrade to 10.7.2, but I'm already there.

  • Create workflow for parking document

    hiiii all can any one tell me in detail, what is the function of  creation of work flow for parking document? and how do i configure? and how do i assign with user? please help menu path :- financial accounting global settings - document - document p

  • Radio Buttons & Check Boxes Replaced w/ Rectangles, when printing Form w/ Adobe Reader XI (11.0.03)

    Hello.  I need to be able to print a .pdf copy of a completed web page form.  The form is completed by entering data into text boxes and text areas, and selecting various radio buttons and check boxes.  When the form is complete, it is saved, which c

  • How can i backup my catalog in PS elements 10

    Backup in photoshop elements 10 continues to baffle me. I go thru the steps as instructed but when my catalog backs up to my external hard drive the files are on in XML format. Where are my pictures? when i attempt to open the file using Photoshop i