Get first week of the month

Hi,
how to get first week of the month from the query
i tried this but not gwtting
SELECT TO_CHAR('09/30/2007','W') FROM DUAL
thanks
Edited by: 896398 on Jan 18, 2012 3:17 AM

896398 wrote:
how to get first week of the monthAssuming week starts Sunday:
SELECT  GREATEST(TRUNC(TRUNC(your_date,'MM') + 1,'IW') - 1,TRUNCyour)date,'MM')) week_start_date,
        TRUNC(TRUNC(your_date,'MM') + 1,'IW') - 1 + 6) week_end_date
  FROM  dual
/ If week starts Monday:
SELECT  GREATEST(TRUNC(TRUNC(your_date,'MM'),'IW'),TRUNCyour)date,'MM')) week_start_date,
        TRUNC(TRUNC(your_date,'MM'),'IW') + 6) week_end_date
  FROM  dual
/ SY.

Similar Messages

  • FM to get first date of the month

    hi,
    any FM to get first day of the month ,  lets say based on input 24.11.2008 , the FM would return 01.11.2008

    Do search in such case(Easy findings).
    https://www.sdn.sap.com/irj/scn/advancedsearch?query=fmtogetfirstdayofthemonth&cat=sdn_all

  • How to get last week of the month from a month

    Hello,
    I want to get last week of the month from a month. For example: If Input = April then Output = Week17. Is there any function module? Or what should be the logic inorder to meet such requirement?
    Thanks in advance for your answers.
    Nitin.

    Hi,
    Just cpoy and past this program, and see the result and apply for you requirements.
    Data: ZSCDATUM TYPE SCDATUM,
          ZKWEEK TYPE KWEEK,
          ZDAY TYPE SY-DATUM,
          ZLDAY TYPE SY-DATUM,
          ZWK(3) TYPE N,
          ZM(2) TYPE N.
          ZDAY = SY-DATUM.
          ZM = ZDAY+4(2).
          CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
            EXPORTING
              day_in                  = ZDAY
            IMPORTING
             LAST_DAY_OF_MONTH       =  ZLDAY
    *       EXCEPTIONS
    *         DAY_IN_NOT_VALID        = 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.
          ZSCDATUM = ZLDAY.
          CALL FUNCTION 'DATE_GET_WEEK'
            EXPORTING
              date               = ZSCDATUM
           IMPORTING
             WEEK               = ZKWEEK
    *       EXCEPTIONS
    *         DATE_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.
          ZWK = ZKWEEK+4(2).
          WRITE: ZKWEEK.
          WRITE: ZWK.
    Thanks
    Reddy

  • How to get first day of the month by the given date?

    Now, is there function in CRM system that can get the first day of the month ?
    for example:
        input date is 2007/12/12, then return 2007/12/01 (the first day of month).
    Thank you~

    Hi ping,
    data: w_date type sy-datum ,
             w_temp(2) type c.
    w_date = '20071212'.
       w_temp = w_date+6(2).
       w_temp = w_temp - 1.
       w_date = w_date - w_temp.
    write / w_date.
    Plz Reward if useful,
    Mahi.

  • How to - get first DAY of the month from the date ?

    Hi
    pls help

    hi,
    data : DAYNR LIKE HRVSCHED-DAYNR,
    DAYTXT LIKE HRVSCHED-DAYTXT.
    data langu like sy-langu value 'EN'.
    Parameters PDATE LIKE SY-DATUM.
    PDATE+6(02) = '01'.
    CALL FUNCTION 'RH_GET_DATE_DAYNAME'
    EXPORTING
    LANGU = LANGU
    DATE = PDATE
    CALID =
    IMPORTING
    DAYNR = DAYNR
    DAYTXT = DAYTXT
    DAYFREE =
    EXCEPTIONS
    NO_LANGU = 1
    NO_DATE = 2
    NO_DAYTXT_FOR_LANGU = 3
    INVALID_DATE = 4
    OTHERS = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    WRITE :/ PDATE, DAYNR, DAYTXT.
       (OR)
    Try..
    DATA:DAYNR  LIKE  HRVSCHED-DAYNR,
         DAYTXT LIKE  HRVSCHED-DAYTXT,
         DAYFREE LIKE  HRVSCHED-NODAY.
    DATA:LANGU LIKE  SY-LANGU ,
         DATE LIKE  SY-DATUM,
         CALID LIKE  P1027-CALID VALUE 'US'.
    date = sy-datum.
    date+6(2) = 01.           "----->to get the first day .
    *first day of the month
    write:/ 'First date of the month', date.
    *Day name
    CALL FUNCTION 'RH_GET_DATE_DAYNAME'
      EXPORTING
        langu                     = SY-LANGU
        date                      = DATE
        CALID                     = CALID
    IMPORTING
       DAYNR                     = DAYNR
       DAYTXT                    = DAYTXT
       DAYFREE                   = DAYFREE
    EXCEPTIONS
       NO_LANGU                  = 1
       NO_DATE                   = 2
       NO_DAYTXT_FOR_LANGU       = 3
       INVALID_DATE              = 4
       OTHERS                    = 5
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    WRITE:/ DAYTXT.
    Don't forget to reward if useful....

  • How to get the first day in the month from a domain date ?

    Hi,
    I like to know how to get the first day in the month from a domain date?
    Thanks
    Stephen

    Hi Gokul...
    Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
    Its similar to the above one but instead of writing case statement you can achive the following.
    data : w_res type i,
             w_data type d,
    w_res = w_date mod 7.
    w_date = w_date - w_res.
    write w_date.
    This works.
    Regards,
    Siddarth

  • From where to get "First day of the week" data for all the locales, is it present in CLDR spec 24?

    I am trying to get "First day of the week" data from CLDR spec24 but cannot find where to look for it in the spec. I need this data to calculate numeric value of "LOCAL day of the week".
    This data to implement "c" and "cc" day formats that equals numeric local day of the week.
    e.g if "First day of the week" data for a locale is 2 (Monday) , it means numeric value for local day of the week will be 1 if it is Monday that day, 2 if it is Tuesday that day and likewise.

    Hi
    If you want to week to be started with Sunday then use the following formula:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}') if it's retail week(starts from Monday) then the follow below:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}')
    I'm assuming var_Date is the presentation variable for prompt...
    Edited by: Kishore Guggilla on Jan 3, 2011 4:48 PM

  • Getting last day of the month

    hi ,
    is there an existing date funtion to get last day of the month ?
    pls advise
    else
    i'll try to add_month + 1 to current month and format to the first day and minus 1 day from that new month
    tks & rdgs

    last_day function
    <br>
    jeneesh

  • Formula to always calculate first week of next month

    Can you please give me pointers regarding the following problem:
    A System generated report that I want to be able to e-mail (no manual parameter selection involved!) . 
    New Customers that have a start date the first week of the following month.
    Using today as an example Monday, JUly 25: create a formula that counts new starts 8/1/2011 - 8/7/2011 and then when it generates again on Monday, August 1: the result should be a count of new starts Sept 1 - sept 7, 2011.... and so forth.

    Hi
    I think you don't have to count True or False by using a formula.  You can very well create record selection formula (filter condition) using the below :
    {ServiceInfo.StartDate} >= DateAdd ("m",1 ,CurrentDate) - DatePart ("d",CurrentDate )+1
    and
    {ServiceInfo.StartDate} <= DateAdd ("m",1 ,CurrentDate) - DatePart ("d",CurrentDate )+7
    This will filter data and can be inserted count without any issues.
    Thanks,
    Sastry

  • First date of the month

    How to calculate the first date of the month on basis of YYYYMM month format ?
    Sanjay

    Hi User,
    If you try using
    SELECT TO_DATE ('201211' || '01', 'ÝYYYMMDD')
      FROM DUAL;We get error as
    >ORA-01821: date format not recognized
    Just Try doing this,
    Convert to CHAR format and Use the Date Function to convert to Date.
    SELECT TO_DATE (TO_CHAR (:STRING || '01'), 'YYYYMMDD')
      FROM DUAL;Input :
    String - 201112
    Output :
    Date
    12/1/2011
    Thanks,
    Shankar

  • Problem in getting exact week of the year (Reposted)

    Hi,
    Can somebody respond to my posting please. I am posting it second time since nobody replied me till yet.
    I make use of below code to get exact week of the year.
    // Assumes the provided date is in 'ddMMM' format
    SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
    Date parsedDate = sdf.parse( dateString );
    Calendar calendar = Calendar.getInstance();
    calendar.setTime( parsedDate );
    int week = calendar.get( Calendar.WEEK_OF_YEAR );
    Problem which I am facing is that when I pass "dateString" as
    "22Mar" then it gives week as 13 instead of 12 for year 2007.
    I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
    cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
    Please help me to understand the resolution. Is it correct or not?
    Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ).
    This seems to be hardcoded for each year.

    What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
            Date parsedDate = sdf.parse( "2007/01/01" );
            Calendar calendar = Calendar.getInstance();
            calendar.setFirstDayOfWeek(Calendar.MONDAY);
            calendar.setTime( parsedDate );
            for (int count = 0; count < 366; count++)
                int week = calendar.get( Calendar.WEEK_OF_YEAR );
                System.out.println(week + "\t" + sdf.format(calendar.getTime()));
                calendar.add(Calendar.DAY_OF_YEAR, 1);
            }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

  • Problem in getting exact week of the year

    Hi,
    I have make of use of below code to get exact week of the year.
    Now problem which I am facing is that when I pass "dateString" as
    "22Mar" then it gives week as 13 instead of 12 for year 2007.
    // Assumes the provided date is in 'ddMMM' format
    SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
    Date parsedDate = sdf.parse( dateString );
    Calendar calendar = Calendar.getInstance();
    calendar.setTime( parsedDate );
    int week = calendar.get( Calendar.WEEK_OF_YEAR );
    I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
    cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
    Please help me out to understand the resolution. Is it correct or not?
    Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ). This seems to be hardcoded for each year.
    Thanks in advance...

    What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
            Date parsedDate = sdf.parse( "2007/01/01" );
            Calendar calendar = Calendar.getInstance();
            calendar.setFirstDayOfWeek(Calendar.MONDAY);
            calendar.setTime( parsedDate );
            for (int count = 0; count < 366; count++)
                int week = calendar.get( Calendar.WEEK_OF_YEAR );
                System.out.println(week + "\t" + sdf.format(calendar.getTime()));
                calendar.add(Calendar.DAY_OF_YEAR, 1);
            }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

  • Repeating Events for the Fifth Week of the Month

    Hello,
    I am attempting to create a calendar schedule to distribute to members of my club. Each member is responsible for a certain day of the month (eg, every first monday).
    iCal gives me the option to select every First, Second, Third, Fourth, or Last weekday of the month for repeating events. Did Apple forget that some months have five weeks in them, or am I really going to have to schedule events for the fifth week manually?
    Thanks,
    -Noel
    Mac Mini   Mac OS X (10.4.8)  

    Hi Noel,
    Welcome to Apple Discussions.
    iCal does not have this feature.
    I tried playing around by scripting the addition of events with the correct rfc2445 recurrence string, but in iCal the events were placed in the first week of the following month on months with four weeks.
    If you want this feature in the future, ask Apple for it.
    Best wishes
    John M

  • Week of the month !!

    Hi,
    how can i get the week of the month so i can use it on queries like a time characteristic ?.
    thanks in advance

    Hi,
    The function module DATE_GET_WEEK gives the week no in that year in 2 digits. By using this function module twice , you can find out the Week in the month.(i.e use FM to calculate week no for month starting date, and use it second time to calculate the week no of the date,and then findout the difference).
    With rgds,
    Anil Kumar Sharma .P

  • Function for finding first day of the month !!

    Hi,
    I know we have function to find the last day(DD) of the month. Do we have any functions for finding the first day of the month ??? if not is there any way i can find the first date(DD) of the month .
    Bcoz i m trying to incorporate the logic for finding the first day of the month partition.
    Thank you!!!

    Shahid Ali Tcs wrote:
    There are many solution given by member in relation with your question, and all are correct .
    I want to make u know something else.
    Have you ever think why oracle has given function for last_day but no function for first.....
    I u think this question u will get the answer of your "first day finding " question.
    Because first day is alwasy 01 of every, while last day can be 30,31,29,28.....
    Got my words ........
    One more solution from my side,,,,
    SQL> select '01' || to_char(sysdate,'-MON-YY') from dual;
    '01'||TO_
    01-SEP-09Which is a completely poor way of doing it.
    Using TRUNC or LAST_DAY(..) + 1 will return a DATE datatype result.
    Your method is converting the DATE into a VARCHAR2, which then prevents further processing/date based calculations unless it is explicitly converted back to a DATE again.
    The reason Oracle hasn't provided a FIRST_DAY is because the TRUNC function already caters for it as this works with DATE's as well as NUMBER's, not because the first day is always 1.

Maybe you are looking for

  • Closing references YES or NO

    Hi all My program contains a cluster with 120 controls (string, Boolean and number). Is it too much? I need visibility or invisibly all controls during the program sometimes. In attachment is a simple example how it is work. Is using block "close ref

  • How do I manging multiple copies of movies for AppleTV and iPod in iTunes?

    I do not have an AppleTV yet, but I am considering getting one. I was wondering how those who have both an iPod and ATV manage the syncing of Movies that may have different resolutions? If I want to have the same movie on ATV and my iPod I would need

  • Game center muti account

    I have an apple id (obviously) and can set up game center on my iphone4. Both my kids have ipod touches and can't have apple id's as they are minors. Hence the three of us seem to have to share the same identity on game center. Is there a way around

  • How can I disable the Reason for Rejection field in VA02 line items

    Hi,   I dont want the users to be able to change the reason for rejection field in the sales order line items. Can someone please suggest a tried and tested way of doing this Thanks for reading.

  • Warning while opening a report

    Hi I am getting a warning while i try to execute a report. The warning says "warning following error for partial InfoCube = 0PCA_C01 in RSDRC_CUBE_DATA_GET_RF, Error SQL Error:1578" Can any one tell me what the issue is and the possible solution ? Re