How to get the date for the first monday of each month

Dear Members,
How to get the date for the first monday of each month.
I have written the following code
SELECT decode (to_char(trunc(sysdate+30 ,'MM'),'DAY'),'MONDAY ',trunc(sysdate+30 ,'MM'),NEXT_DAY(trunc(sysdate+30 ,'MM'), 'MON')) FROM DUAL
But it look bith complex.
Abhishek
Edited by: 9999999 on Mar 8, 2013 4:30 AM

Use IW format - it will make solution NLS independent. And all you need is truncate 7<sup>th</sup> day of each month using IW:
select  sysdate current_date,
        trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month
  from  dual
CURRENT_D FIRST_MON
08-MAR-13 04-MAR-13
SQL> Below is list of first monday of the month for this year:
with t as(
          select  add_months(date '2013-1-1',level-1) dt
            from  dual
            connect by level <= 12
select  dt first_of_the_month,
        trunc(dt + 6,'iw') first_monday_the_month
  from  t
FIRST_OF_ FIRST_MON
01-JAN-13 07-JAN-13
01-FEB-13 04-FEB-13
01-MAR-13 04-MAR-13
01-APR-13 01-APR-13
01-MAY-13 06-MAY-13
01-JUN-13 03-JUN-13
01-JUL-13 01-JUL-13
01-AUG-13 05-AUG-13
01-SEP-13 02-SEP-13
01-OCT-13 07-OCT-13
01-NOV-13 04-NOV-13
FIRST_OF_ FIRST_MON
01-DEC-13 02-DEC-13
12 rows selected.
SQL> SY.

Similar Messages

  • How to get the date for the last day of a week?

    Is there a easy way to get the date for the last day of week?
    eg a week starts on monday and end on sunday
    January 11, 2005 is the start date for the week
    January 17, 2005 is the end date for the week
    or
    say
    February 26, 2003 is the start date for the week
    March 5, 2003 is the end date for the week
    I just need a simple way of figuring that out....
    I figured out how to get the start date for the week but just can't get the latter..
    formatting of the date is not of a concern.. that I know how to do
    thanks in advance

    How about something like the following?
         Calendar someDay = new GregorianCalendar(2005,0,11);//2005 Jan, 11
         //Note above that January is 0, not 1, as counting starts from 0.
          someDay.add(Calendar.DAY_OF_MONTH,6); //add 6 days
         java.util.Date  lastDayOfWeek = someDay.getTime();
         //If someDay was the start of a week, lastDayOfWeek should now be
         //the last day of that week.
         System.out.println(lastDayOfWeek.toString() );

  • How to get last date of the week

    hi,
    how to get last date of the week like FM WEEK_GET_FIRST_DAY gives the date of the first day of the week i need the date of the last day of the week..
    thnx

    data : p_week type KWEEK,
    p_Date type SYDATUM.
    p_week = <incoming value in week of year>
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
    EXPORTING
    week = p_week
    IMPORTING
    DATE = p_date
    EXCEPTIONS
    WEEK_INVALID = 1
    OTHERS = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    To get the last day of the week.
    p_date = p_date + 6.
    You can find the available fm in the system from se37 transaction code.

  • How to get Open Balance for the year and Total Ending Balance?

    For a given account, how to get Open Balance for the year (Cumulative Ending Balance) and Total Ending Balance (Cumulative Ending Balance)?
    Is there any function module available? or should I read from some tables? Please advice.

    Hello Paul,
    You could try calling one of the following BAPIs - see which one meets your requirement. They are documented well so shouldn't be a problem finding out the correct one for your requirements.
    BAPI_GL_GETGLACCBALANCE      
    BAPI_GL_GETGLACCCURRENTBALANCE
    BAPI_GL_ACC_GETBALANCE      
    BAPI_GL_ACC_GETCURRENTBALANCE
    BAPI_GL_ACC_GETPERIODBALANCES
    BAPI_COND_VAL_DECRE_BALANCES
    You might have to put in some of your own logic after the BAPI call to get what you want.
    Hope this helps,
    Cheers,
    Sougata.
    p.s. Also look at FM FAGL_GET_ACCOUNT_BALANCE
    Edited by: Sougata Chatterjee on May 7, 2008 11:47 AM

  • How to set the filter on a report to show the data for the Current Month

    Hi all,
    I am working on a report, which currently has this filter: Date First Worked is greater than or equal to 10/01/2010. This reports show the data for the current month, so at the beginning of each month we have to remember to change the date on the filter.
    Does anyone know what the criteria should say, so that it automatically changes and shows the information for the current month, without us having to go in and change anything?
    Any help would be greatly appreciated!
    Thanks,
    AA

    You need to add a session variable to date fir worked assuming that this is a date field.
    To do this open up the filter on the field then at then press add Variable then "session" and enter the following CURRENT_MONTH into the Server Variable section.

  • NT - How to embed the date for the export output file?

    I want to know how to embed a date for the export file on Windows NT?
    Example :
    In Unix you can use a shell variable and attach to the file like exp file=exp_prod_$A,
    where $A will have the system date, My output will be like exp_prod_10012000.dmp.
    I want to know how to do the above on NT.
    Thanks
    Ravi
    null

    Welcome to the forum!
    When you want to post a block of code, you can enclose it with the mark ups { code }
    That is the key word code surrounded by curly brackets, but without the spaces
    You seem to be running a very old (and unsupported release of the database)
    7.3 has not been a current release for about 10 years.
    It's probably been that long since I've used this technique, but i think it should work.
    You should consider welcoming your system to the 21st century by upgrading to a supported release ;-)
    If you used split to chop up your export file, use cat or dd to reassemble it.
    So, something like this:
    mknod bk.dmp p
    cat xaa xab xac xad xae xaf xag xah xai > bk.dmp &
    imp SYSTEM/$PASSWD parfile=imp_bk.parfile
    rm bk.dmp
    $ cat imp_bk.parfile
    file=bk.dmp
    log=imp.log
    full=y
    buffer=1048576
    ignore=y
    commit=y let us know if still have problems.
    Good Luck!

  • Problem while refreshing the data for the second time using excel services in sharepoint 2013...

    Hi,
    I have migrated my Sharepoint from 2010 to 2013.I am able to get the data at the first time of refresh when I click on refresh for the second time I am getting the empty the sheet.
    below find the flow of refresh
    First Refresh
    On Click of refresh open the workbook with excel services and return the session id.
    Using that session I am invoking RefrehAsync method of excel services
    After refresh completed I am setting the calculation of workbook as automatic(to calculate the formulas) using the same session id
    After setting the calculation as Automatic I am setting the calculation type as full(recalculate) using the same session id.
    Now I am able to see the data
    Second Refresh
    After clicking on refresh instead of opening the workbook I am using the session id(already opened workbook) and setting the calculation type as manual
    I am following the same process from refresh(RefreshAsync) as I have followed in first refresh.
    This time my formulas are not getting calculated because of that I am not able to see the data.
    Could you please let me know that am I missing anything here?
    Is this know issue in Sharepoint2013 excel services as same code is working fine with Sharepoint2010.
    If I close the workbook(session id null) and opens(new session id) for all the refreshes it is working and I am able to see the data.
    Thanks,
    Meenakshi Nagpal
    N.Meenakshi

    I am able to see the data for the second refresh  if I change the data source.If I use the same data source which is used in the first refresh I am not getting the data.Excel services will contact the cubes and calculate the formulas in my workbook.
    Could you please let me know what could be the problem at second refresh while contacting the same data source with same session id?
    Please help me asap.
    Thanks,
    Meenakshi Nagpal
    N.Meenakshi

  • How to Get Missing Dates for Each Support Ticket In My Query?

    Hello -
    I'm really baffled as to how to get missing dates for each support ticket in my query.  I did a search for this and found several CTE's however they only provide ways to find missing dates in a date table rather than missing dates for another column
    in a table.  Let me explain a bit further here -
    I have a query which has a list of support tickets for the month of January.  Each support ticket is supposed to be updated daily by a support rep, however that isn't happening so the business wants to know for each ticket which dates have NOT been
    updated.  So, for example, I might have support ticket 44BS which was updated on 2014-01-01, 2014-01-05, 2014-01-07.  Each time the ticket is updated a new row is inserted into the table.  I need a query which will return the missing dates per
    each support ticket.
    I should also add that I DO NOT have any sort of admin nor write permissions to the database...none at all.  My team has tried and they won't give 'em.   So proposing a function or storable solution will not work.  I'm stuck with doing everything
    in a query.
    I'll try and provide some sample data as an example -
    CREATE TABLE #Tickets
    TicketNo VARCHAR(4)
    ,DateUpdated DATE
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-01')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-05')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-07')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-03')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-09')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-11')
    So for ticket 44BS, I need to return the missing dates between January 1st and January 5th, again between January 5th and January 7th.  A set-based solution would be best.
    I'm sure this is easier than i'm making it.  However, after playing around for a couple of hours my head hurts and I need sleep.  If anyone can help, you'd be a job-saver :)
    Thanks!!

    CREATE TABLE #Tickets (
    TicketNo VARCHAR(4)
    ,DateUpdated DATETIME
    GO
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-01'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-05'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-07'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-03'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-09'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-11'
    GO
    GO
    SELECT *
    FROM #Tickets
    GO
    GO
    CREATE TABLE #tempDist (
    NRow INT
    ,TicketNo VARCHAR(4)
    ,MinDate DATETIME
    ,MaxDate DATETIME
    GO
    CREATE TABLE #tempUnUserdDate (
    TicketNo VARCHAR(4)
    ,MissDate DATETIME
    GO
    INSERT INTO #tempDist
    SELECT Row_Number() OVER (
    ORDER BY TicketNo
    ) AS NROw
    ,TicketNo
    ,Min(DateUpdated) AS MinDate
    ,MAx(DateUpdated) AS MaxDate
    FROM #Tickets
    GROUP BY TicketNo
    SELECT *
    FROM #tempDist
    GO
    -- Get the number of rows in the looping table
    DECLARE @RowCount INT
    SET @RowCount = (
    SELECT COUNT(TicketNo)
    FROM #tempDist
    -- Declare an iterator
    DECLARE @I INT
    -- Initialize the iterator
    SET @I = 1
    -- Loop through the rows of a table @myTable
    WHILE (@I <= @RowCount)
    BEGIN
    --  Declare variables to hold the data which we get after looping each record
    DECLARE @MyDate DATETIME
    DECLARE @TicketNo VARCHAR(50)
    ,@MinDate DATETIME
    ,@MaxDate DATETIME
    -- Get the data from table and set to variables
    SELECT @TicketNo = TicketNo
    ,@MinDate = MinDate
    ,@MaxDate = MaxDate
    FROM #tempDist
    WHERE NRow = @I
    SET @MyDate = @MinDate
    WHILE @MaxDate > @MyDate
    BEGIN
    IF NOT EXISTS (
    SELECT *
    FROM #Tickets
    WHERE TicketNo = @TicketNo
    AND DateUpdated = @MyDate
    BEGIN
    INSERT INTO #tempUnUserdDate
    VALUES (
    @TicketNo
    ,@MyDate
    END
    SET @MyDate = dateadd(d, 1, @MyDate)
    END
    SET @I = @I + 1
    END
    GO
    SELECT *
    FROM #tempUnUserdDate
    GO
    GO
    DROP TABLE #tickets
    GO
    DROP TABLE #tempDist
    GO
    DROP TABLE #tempUnUserdDate
    Thanks, 
    Shridhar J Joshi 
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • In mdx how to get max date for all employees is it posible shall we use group by in mdx

    in mdx how to get max date for all employees is it posible shall we use group by in mdx
    example
    empno  ename date
    1         hari        12-01-1982
    1         hari        13-06-2000
    by using above data i want to get max data

    Hi Hari3109,
    According to your description, you want to get the max date for the employees, right?
    In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
    http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
    If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

  • 大家帮帮忙呀,真是苦恼呀!The date for the prompt 'startDate' is invalid. (WIS 10706)

                   IInfoObject report = (IInfoObject) objects.get(0);
                   IWebi webi = (IWebi) report;
                   // u83B7u5F97u63D0u793Au53C2u6570
                   di = getReportEngine().openDocument(report.getID());
                   di.refresh();
                   // u8BBEu7F6Eu53C2u6570
                   if (params != null)
                        Prompts prompts = di.getPrompts();
                        int promptNum = prompts.getCount();
                        for (int j = 0; j <= promptNum - 1; j++)
                             Prompt p = (Prompt) prompts.getItem(j);
                             if(params.get(p.getName())!=null)
                                  //u68C0u6D4Bu662Fu5426u5E26u6709u7A7Au5B57u7B26
                                  String temp[]=(String[])params.get(p.getName());
                                  boolean falg=false;
                                  for(int len=0;len<temp.length;len++)
                                       if(temp[len]==null)
                                            falg=true;
                                       else if("".equals(temp[len].trim()))
                                            falg=true;
                                  if(falg)
                                       continue;
                                  //u5BF9u65E5u671Fu6570u7EC4u8FDBu884Cu8F6Cu6362
                                  if("DATE".equalsIgnoreCase(p.getObjectType().toString()))
                                       String formatStr=p.getInputFormat();
                                       for(int x=0;x<temp.length;x++)
                                            temp[x]=DateUtil.DateToString(DateUtil.StringTODate(temp[x]),formatStr);
                                  System.out.println(p.getName()+"u503C  "+temp[0]);
                                  p.enterValues(temp);
                        PromptsUtil.populateWebiPrompts(di.getPrompts(), webi);
                   // u540Eu7F00u540Du79F0
                   if (format !=EXCEL && format != PDF && format !=Webi)
                        throw new Exception(" u751Fu6210u62A5u8868u5B9Eu4F8Bu683Cu5F0F,u53EAu63A5u6536EXCEL,PDF,Webiu683Cu5F0Fu53C2u6570!");
                   webi.getWebiFormatOptions().setFormat(format);
                   ISchedulingInfo scheduleInfo = report.getSchedulingInfo();
                   scheduleInfo.setType(0);
                   //u662Fu5426u53D1u9001u90AEu4EF6
                   if(isSendMail)
                        doSendMail(scheduleInfo,report,
                                  format,message,title,recipientAddresses,CCAddresses);
                   //u8BBEu7F6Eu81EAu5B9Au4E49u503C
                   if(properties!=null && !"".equals(properties))
                        report.properties().setProperty(CUSTOMVALUE,properties);
                   scheduleInfo.setRightNow(true);
                   // u751Fu6210u5B9Eu4F8B
                   getIInfoStore().schedule(objects);
    上述代码片段为BO生成实例的过程,程序不会出错。但BO报表历史记录中,提示:The date for the prompt 'startDate' is invalid. (WIS 10706)
    刚开始认为:日期格式错误,我便加上了
    if("DATE".equalsIgnoreCase(p.getObjectType().toString()))
           String formatStr=p.getInputFormat();
           for(int x=0;x<temp.length;x++)
                  temp[x]=DateUtil.DateToString(DateUtil.StringTODate(temp[x]),formatStr);
    需且验证日期格式,正是p.getinputFormat()所要求的格式,可BO历史记发中,生成实例还是报上述错误。
    Edited by: pyantking on Jul 27, 2009 2:39 PM

    Hello Anh,
    With XI 3.1 some significant fixes were delivered to address issues like you describe : create a query with QaaWS Designer using date input parameters (prompts) with a given locale, then edit (with QaaWS Designer) the query under another different locale, where dates are set with a different format.
    AFAIK QaaWS queries keep the locale under which they were created, fixes were aimed at translating input parameters in the right format so errors like the one you describe should not be encountered.
    i suggest you get in touch with the SAP BusinessObjects tech support with your issue, so we will be able to investigate further in conjunction with QaaWS dev team and work out a fix, if this turns out to be a bug.
    BTW, Have you considered upgrading to a more recent Service Pack? Business Objects Enterprise XI 3.1 SP3 is now available since 2010 Q2 (no guarantee, though, that this issue would be solved with this SP)
    Hope that helps,
    David.

  • Unable to see the data for the hierarchy in rsa3

    Hi Gurus,
    i am trying to check the data for the standard hierarchy in rsa3,but it is showing an  error message saying that error 6 in functional module rss_program_generate.Please help me out.
    thanks
    bhaskar

    Check if this helps seemed relevant
    Error 6 in function module RSS_PROGRAM_GENERATE
    Error 6 in function module RSS_PROGRAM_GENERATE
    error Error 6 in function module RSS_PROGRAM_GENERATE

  • Function module to determine the date for the nth weekday of the mth month

    Hey folks,
    Is there a function module which determines the date for the mth weekday of the nth month in the pth year.
    For instance, if I input 2nd thursday of the 4th month in 2008, it should return me, 04/10/2008  (MM/DD/YYYY).
    Thanks and Best Regards,
    Puja.

    Hi Ravi,
    Hadn't been able to work on this lately...You solution was quite close, but did not work for a few scenarios....I tweaked the logic a bit to take care of them as well...
    So here goes the code:
    ================================================
      DATA first_day_of_month TYPE datum.
      DATA day TYPE p.
      CONCATENATE year month '01' INTO first_day_of_month.
      CALL FUNCTION 'DAY_IN_WEEK'
        EXPORTING
          datum = first_day_of_month
        IMPORTING
          wotnr = day.
      DATA day_number TYPE numc2.
      IF day = weekday.
        IF recur = 1.
          DATA ls_date(10) TYPE c.
          CONCATENATE month '/01/' year INTO ls_date.
          CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
            EXPORTING
              date_external                  = ls_date
           IMPORTING
             date_internal                  = date.
        ELSE.
          day_number =  ( ( recur - 1 ) * 7 )  + 1.
        ENDIF.
      ELSEIF day < weekday.
        day_number = ( ( recur - 1 ) * 7 ) + ( weekday - day ) + 1.
      ELSE.
        day_number = ( ( recur - 1 ) * 7 ) + ( 7 - day ) + weekday + 1.
      ENDIF.
      IF date IS INITIAL.
        CONCATENATE year month day_number INTO date.
      ENDIF.
    ====================================
    There still could be some loopholes in this....am not sure....but it sure did seem to work for a couple of random checks that I performed.
    Brownie points to you for giving me a direction.
    Thanks,
    Puja.

  • How to get current date for posting date

    hi,
    how to get current date for posting date ? any sample code ?
    Thanks

    Hi......
    Use
    Select getdate()
    for current date.......
    Regards,
    Rahul

  • Which tables are being used to extract the data for the materi Extractors

    Hi
    please advise which tables are used to extract the data for the extarctors
    0MAT_SALES_ATTR,
    0MATERIAL_ATTR,
    0MAT_PLANT_ATTR
    0PLANT_ATTR
    ,Many thanks.

    Hi,
    Activate a database trace using ST01. Then perform the MM03 operation and goto the SD Texts tab. Now stop the trace and see if you can locate either a table or program which you can utilize in the log.
    http://help.sap.com/saphelp_47x200/helpdata/en/dd/55f993545a11d1a7020000e829fd11/frameset.htm
    Hope this helps..
    Rgs,
    Ravikanth.

  • How to approach in getting the dates for the user given periods

    Hi All,
    I have areuirement where the calendar would be like as 466 for a period
    for eg. period 1(Jan) has 4 weeks
    period 2(Feb) has 6 weeks
    period 3(Mar) has 6 weeks
    again period 4(Apr) has 4 weeks
    period 5(May) has 6 weeks
    period 6(June) has 6 weeks
    How to get the dates (from date and end date) for the periods.
    Anybody's help will be appreciated
    Regards
    Saugata

    I have areuirement where the calendar would be like as 466 for a periodWhat does that mean? Is 466 the format of the data?
    The end date depends on the start date. This query might be helpful for you
    SQL> WITH data AS(
      2    SELECT 1 period, 4 duration FROM dual UNION ALL
      3    SELECT 2, 6 FROM dual UNION ALL
      4    SELECT 3, 6 FROM dual UNION ALL
      5    SELECT 4, 4 FROM dual UNION ALL
      6    SELECT 5, 6 FROM dual UNION ALL
      7    SELECT 6, 6 FROM dual)
      8  SELECT
      9    period,
    10    duration,
    11    SYSDATE + SUM(duration) OVER (ORDER BY period RANGE UNBOUNDED PRECEDING) * 7 AS end_date
    12  FROM data
    13  ;
        PERIOD   DURATION END_DATE
             1          4 16-NOV-07
             2          6 28-DEC-07
             3          6 08-FEB-08
             4          4 07-MAR-08
             5          6 18-APR-08
             6          6 30-MAY-08
    6 rows selected.
    SQL>

Maybe you are looking for

  • Wifi not working iPhone 4s

    Wifi is not working any more on my iPhone 4S ! Two days after updating to iOS7.1, wifi is not working any more on my 2 years old iPhone 4S. Searching google, iOS7.1 is a major problem for many iPhone 4S. Resetting network connection as recommended by

  • To_number() with format pattern and nvarchar2

    Hi, I've had a problem with converting a number in US format in to a number. Due to the settings of our Oracle we have German locale settings. Thus I use the NLS format parameters in the to_number function. It works pretty well if I set the number st

  • Portal 7 on Solaris 10 x86

    I am trying to setup a demo of Portal Server 7 on a laptop running Solaris 10 x86. I have tried both non-global and global zones and I continue to get the same results. The installer seems to complete successfully. However when I access http://server

  • Aim account wont login on ichat

    i have switched to leopard over the weekend. Since doing so, i have been unable to get my aim account to login. I receive the message connection reset by peer. I have no idea what to do, because i can get connected w/ adium to my msn account but not

  • Sending Alerts from PC

    Hello All, I am working on sending alerts from PC, I followed below steps. 1. Go to ALRTCATDEF 2. Select classification "Process Chains" 3. Click on display/change 4. Double-click on "error in a process of a process chain" 5. Click on "fixed recipien