First and Last date of any Month.

Hi Friends,
I have 2 fields in my table
FROM DATE & TO DATE
User can enter any date in these two fields, but at time of commit i want to change the FROM DATE to the first date of the Month user have entered. And for TO DATE i want to change the last date of the month.
For Example :
User Enters-
FROM DATE 12-Mar-2003
TO DATE 27-Jun-2003
I want to change these date to:
FROM DATE 01-Mar-2003
TO DATE 30-Jun-2003
How can I write a database function or procedure to control this thing.
Please help.
Best regards,
Imran Baig

It depends on your requirements, but I usually use TRUNC(date, 'D')
to get the first day(Sunday) of the week, because TRUNC(date, 'W')
returns the same day of the week as the first day of the month.
See http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/function.htm#80101
for more info on this.

Similar Messages

  • Getting first and last dates of a month

    Jello all,
    I am really sorry I am posting this topic here, not actually owned by this forum but in fundamental forum i am not getting it attended.
    I am generating monthly, quartelry and yearly reports, for which I need to get first and last dates of a given Month taking in to account leap year. I searched the API and docs for Calendar class. I could not find any useful methods / fields. I wonder this being a very common requirement, how SUN has not provided these essential features. I still feel, it must be some where. Please help me and reply. Also if you came across any other forum for util package, let me know.
    Thanks
    Varde

    Jello all,
    I am really sorry I am posting this topic here, not
    actually owned by this forum but in fundamental forum
    i am not getting it attended.
    Yes, and I can see you are a very patient person, waiting a whole half hour for a response before cross posting other boards.
    Question answered.
    http://forum.java.sun.com/thread.jsp?thread=514908&forum=31&message=2451646

  • How to get first and last date of previous month

    To set default values in selection screen,I want first and last date of the previous month.
    Also I want the first and last dates of previous quarter.
    The quarters can be only january to march, apr to june, jul to sept, oct to dec.
    I want to run a program on beginning of each month by job scheduling having <b>selection screens</b> for the above monthly and quarterly dates.

    Hi Suhas,
    Use the below code.
    DATA: v_date LIKE sy-datum.
    DATA: v_month_begin_date TYPE sy-datum,
          v_month_end_date TYPE sy-datum,
          v_month(2) TYPE n,
          v_month1(2) TYPE n,
          v_quarter TYPE i,
          v_year(4) TYPE n,
          v_quarter_begda TYPE sy-datum,
          v_quarter_endda TYPE sy-datum.
    v_month =  sy-datum+4(2).
    IF v_month = '01'.
      v_month = '12'.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_month = v_month - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CONCATENATE v_year v_month  '01' INTO v_date.
    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
      EXPORTING
        iv_date             = v_date
      IMPORTING
        ev_month_begin_date = v_month_begin_date
        ev_month_end_date   = v_month_end_date.
    v_month1 = sy-datum+4(2).
    IF v_month1 = '01' OR
       v_month1 = '02' OR
       v_month1 = '03'.
      v_quarter = 1.
    ELSEIF v_month1 = '04' OR
           v_month1 = '05' OR
           v_month1 = '06'.
      v_quarter = 2.
    ELSEIF v_month1 = '07' OR
           v_month1 = '08' OR
           v_month1 = '09'.
      v_quarter = 3.
    ELSEIF v_month1 = '10' OR
           v_month1 = '11' OR
           v_month1 = '12'.
      v_quarter = 4.
    ENDIF.
    IF v_quarter = 1.
      v_quarter = 4.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_quarter = v_quarter - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CALL FUNCTION 'HR_99S_GET_DATES_QUARTER'
      EXPORTING
        im_quarter = v_quarter
        im_year    = v_year
      IMPORTING
        ex_begda   = v_quarter_begda
        ex_endda   = v_quarter_endda.
    WRITE:/5 'previous month begin date : ', v_month_begin_date.
    WRITE:/5 'previous month end date   : ', v_month_end_date.
    WRITE:/5 'previous quarter begin date : ', v_quarter_begda.
    WRITE:/5 'previous quarter end date : ', v_quarter_endda.
    Message was edited by:
            Velangini Showry Maria Kumar Bandanadham

  • How  we claculate the first and last date of the month

    hi,
    I have a requirement, if i have the any date of a month like today date 02/13/2008. So i want the first date of this month and the last date of this month.
    Is there any FM for this..or if you have nay prorgam pls send to me.
    thanks.

    Hi Vipin,
    Try
    HR_JP_MONTH_BEGIN_END_DATE FM will return both first day and last day
    LAST_DAY_OF_MONTHS  for getting last day of month.
    Reward if helpful.
    Regards,
    Mandeep

  • To display first and last dates of a month

    I have the date format in 10 Mar 10.
    My requirement is when ever I select the any date in the dashboard for whole month it should display whole month results.
    I got query in obiee101.blogspot.com.but if I use that sometimes it is not returning the last day results. Any body please give me the query to display results for first day and lastday?
    Ex:if I select any day in the drop down of the prompt it should display whole month results
    If I select either 1 mar 10,2 mar 10,30 mar 10.....
    It should give the results for whole month of march.
    Can you please provide me the query for last month also?
    If I select march date in date print want to display whole march results in one column,previous month results in other column
    Anybody help me to get this done?

    Yes, you are correct. In John's SQL for last day of the month, if the "last day of the previous month" ends on the 30th, than "adding one month" will result in the 30th of the following month. But if the following month has 31 days, you miss that day.
    Use this for the last day of the current month.
    TIMESTAMPADD(SQL_TSI_DAY, -1,TIMESTAMPADD(SQL_TSI_MONTH,1,TIMESTAMPADD(SQL_TSI_DAY,1,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))))
    The above SQL will ensure that you will always get the last day of the "current month" regardless of how many days are in the previous or current month.

  • First and Last Date.  Is is possible in Essbase?

    Hello All,<BR><BR>Here are the dimensions in my outline:<BR>- User<BR>- Application<BR>- Dates<BR>- Measures (Count, FirstLoginDate, LastLoginDate)<BR><BR>I am trying to create a report in Essbase that shows the first and last date that each user accessed each Essbase application. I created an ETL process that builds a relational table with one record for each unique combination of User/Application/Day where a user was logged into an application. This process gets its source data from the Essbase application log files. I am loading a count of 1 to each intersection of User/Application/Day. I also want to add the first and last day to the cube but can not figure out how.<BR><BR>1) Is there an easier way to get at the source data then the application log files?<BR>2) If the application log files are the way to go, how do I indicate in the cube what the first and last login days are for each combination of User/Application?<BR><BR>I was thinking of loading the serial dates to the FirstLoginDate and LastLoginDate measures. The trouble I am having is where to load the dates data. Do I load it to level 0 (individual dates) and then use time balance to get the dates up to the higher levels (month, year) or load it at the higher levels? If I should load it at the higher levels, do I assume correctly I will need to create another relational table with one record for each User/Application/Month and User/Application/Year that shows the first and last dates? Any other ideas?<BR><BR>Thank you in advance,<BR><BR>Bill Handelman<BR>847-989-1758<BR>[email protected]<BR><BR>

    While you may have natural ordering in your date dimensions, Essbase doesn't handle first and last dates well. The one area where ther is at least some funcionality in date manipulation is inattribute dimensions, however, the easy use there allows only one date attribute using normal date processing. It gets a great deal more complex using two dates.<BR><BR>Look up the DBAG references to the date type of attribute dimensions, you might find it a partial solution to your problem.<BR><BR>If you go the serial date method, load at level 0 and want to use time balance to bring the values up, you still need a time dimension. If I were designing something, I might use the first access date as a time dimension and the last access date in an attribute dimension, but I'm rambling rather than analyzing.<BR><BR>In any case, look at the date type attribute dimension as one possible option for your cube.

  • Get first and last date of month

    Hi,
      Is there any function module to get first and last date of month for a entered date.
    Please let me know.
    Regards,
    SP

    Hi,
    Use the below FM to find the Last day of month and them u can easily calculate the first day.
    DATA : v_startdate TYPE sy-datum.
    DATA : v_enddate TYPE sy-datum.
    DATA : v_temp TYPE dats.
    v_temp = sy-datum.
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
        EXPORTING
          day_in            = v_temp
        IMPORTING
          last_day_of_month = v_enddate
    CONCATENATE  v_enddate+0(6)  '01'  INTO  v_startdate.
    Hope it helps.
    Regards,
    Arnab.

  • How to find first and last date of a fiscal week using SQL

    Hello,
    I want information about FISCAL Week, means a Week based on ISO standard. I know format strings ‘IW’ or ‘IYYY’ gives fiscal week and fiscal year respectively from a given date. But I want to find the first and last date of a fiscal week. Say suppose I have a fiscal week is 2, and fiscal year is 2008, how to find the start and end date of the given fiscal week.
    Any kind of help would be greatly appreciable.
    Thanks,
    Prince

    davide gislon wrote:
    The following query evaluate the begin of a fisical week, where &year and &week are respectively the year and week you want to calculate.
    To evaluate the end of the week you have to add 6.
    Note that my database is set to have monday as day number 1 of the week, and sunday as day number 7; if your database settings are different you should modify the query accordingly.
    SELECT CASE TO_CHAR(TO_DATE('&year','YYYY'),'D')
    WHEN '1' THEN TO_DATE('&year','YYYY')+((&week-1)*7)
    WHEN '2' THEN TO_DATE('&year','YYYY')+((&week-1)*7-1)
    WHEN '3' THEN TO_DATE('&year','YYYY')+((&week-1)*7-2)
    WHEN '4' THEN TO_DATE('&year','YYYY')+((&week-1)*7-3)
    WHEN '5' THEN TO_DATE('&year','YYYY')+((&week-1)*7+3)
    WHEN '6' THEN TO_DATE('&year','YYYY')+((&week-1)*7+2)
    WHEN '7' THEN TO_DATE('&year','YYYY')+((&week-1)*7+1)
    END BEGIN_FISICAL_WEEK
    FROM DUAL
    Hope this is helpful.
    Cheers,
    Davide
    Edited by: davide gislon on 08-Jan-2009 07:19Your query does nothing you say it does. TO_DATE('&year','YYYY') returns first day of the current month for year &year. And the only reason it returns January 1, &year is that we are currently in January:
    SQL> select TO_DATE('&year','YYYY') from dual
      2  /
    Enter value for year: 2005
    old   1: select TO_DATE('&year','YYYY') from dual
    new   1: select TO_DATE('2005','YYYY') from dual
    TO_DATE('
    01-JAN-05
    SQL> As soon as we roll into February:
    SQL> alter system set fixed_date = '2009-2-1' scope=memory
      2  /
    System altered.
    SQL> select sysdate from dual
      2  /
    SYSDATE
    01-FEB-09
    SQL> select TO_DATE('&year','YYYY') from dual
      2  /
    Enter value for year: 2005
    old   1: select TO_DATE('&year','YYYY') from dual
    new   1: select TO_DATE('2005','YYYY') from dual
    TO_DATE('
    01-FEB-05
    SQL> alter system set fixed_date = NONE scope=both
      2  /
    System altered.
    SQL> select sysdate from dual
      2  /
    SYSDATE
    08-JAN-09
    SQL> But even if TO_DATE('&year','YYYY') would always return January 1, &year, or you would fix it to TO_DATE('0101&year','MMDDYYYY') it still would be wrong. ISO week rules are
    If January 1 falls on a Friday, Saturday, or Sunday, then the week including 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 week is the first week of the new year, because most of the days in the week belong to the new year.Therefore, next year:
    SQL> DEFINE YEAR=2010
    SQL> DEFINE WEEK=1
    SQL> ALTER SESSION SET NLS_TERRITORY=GERMANY -- enforce Monday as first day of the week
      2  /
    Session altered.
    SQL> SET VERIFY OFF
    SQL> SELECT CASE TO_CHAR(TO_DATE('0101&&year','MMDDYYYY'),'D')
      2  WHEN '1' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7)
      3  WHEN '2' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-1)
      4  WHEN '3' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-2)
      5  WHEN '4' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7-3)
      6  WHEN '5' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+3)
      7  WHEN '6' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+2)
      8  WHEN '7' THEN TO_DATE('0101&&year','MMDDYYYY')+((&&week-1)*7+1)
      9  END BEGIN_FISICAL_WEEK
    10  FROM DUAL
    11  /
    BEGIN_FI
    04.01.10
    SQL> SELECT TRUNC(TO_DATE('0101&&year','MMDDYYYY'),'IW') FROM DUAL
      2  /
    TRUNC(TO
    28.12.09
    SQL> 2 user10772980:
    Use:
    SELECT  TRUNC(TO_DATE('0101&&year','MMDDYYYY'),'IW') + (&&week-1)*7 FISCAL_YEAR_&&YEAR._WEEK_&&WEEK
      FROM  DUAL
    FISCAL_YEAR_2010_WEEK_1
    28.12.09
    SQL> SY.

  • How to find first and last day of previous month?.

    Based on current month, I want to find start and end day of
    previous month.
    For example,
    For august, Start date is July 1st and End date July 31st.
    How can i get first of previous month as start date and last
    day of the previous month as end date?.
    Same way,
    i want to find start date of current month and end date of
    next month.
    Example:
    For august,
    i want to get start date, august 1st and end date : september
    30.
    How can i do this from current date or now().
    I am looking for best and easy way to find start and end
    dates..
    Thanks

    <cfset today = now()>
    <cfset firstOfThisMonth = createDate(year(today),
    month(today), 1)>
    <cfset lastOfNextMonth = dateAdd("d", -1, dateAdd("m", 2,
    firstOfThisMonth))>
    <cfoutput>
    today = #today#<br>
    firstOfThisMonth = #firstOfThisMonth#<br>
    lastOfNextMonth = #lastOfNextMonth#<br>
    </cfoutput>
    Edit - To find the start and end day of previous month, get
    the first of THIS month. Use Subtract 1 month ("m") to get the
    start date. Subtract 1 day ("d") to get the end date.

  • Expression - First date and last date of current month, current year

    Hi
    I need to have 2 ssrs expression as I can use  as default parameters in my report where I can -  out from my Time dimension, get the
    first date of the current, current year - and one where I get last date, current month, current year.
    My data source is a SSAS cube and my timedimension is structured like this:
    [Time].[Days].&[2009-01-16T00:00:00]
    Any suggestions how to solve this ?

    Hi ,
    You can use below in Default Values in ssrs ;
    for first Day of current month and year
    ="[Time].[Days].&[" +Format(dateadd("m",0,dateserial(year(Today),month(Today),1)), "yyyy-MM-dd")+"T00:00:00]"
    output will be ;
    [Time].[Days].&[2014-09-01T00:00:00]
    For last day of current month and year
    ="[Time].[Days].&[" +Format(DateSerial(Year(Now()), Month(Now()), "1").AddMonths(1).AddDays(-1), "yyyy-MM-dd")+"T00:00:00]"
    output will be ;
    [Time].[Days].&[2014-09-30T00:00:00]
    Please correct me if I misunderstood your requirement.
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem.

  • First and last values of this month

    Hi ,
    In my reporting I want to calculate average value based on amount.
    Avg = ( Starting amount of this month + Ending amount of this month) / 2.
    How can i get the starting value and ending value for one field "Amount".
    I changed the <b>amount</b> properties as Sum, Last value and based 0calday.
    but for the same amount how can I get the starting value.
    (NOTE: Starting value is not equal to the last month last value).
    The data is coming based on day wise.
    Suggest me ...
    Thanks in advance....
    Regards
    Rajesh

    Dear Rajesh,
    Can you tell me which cube you are working with, and what is the key figure ?
    What you can do is have a RKF which will have a selection variable for fiscal year period for the current month(which could be a user entry and mandatory entry).
    Now create a copy of the above RKF and use a off set of -1 for the variable fiscal year period.
    now the valu you get from the first RKF will be the month end balance and the value you get for the second RKF will be the closing balance of previous month, which is nothing but the opening for the user inputed month.
    Now you can create a CKF to get the average.
    Hope the above helps, If yes please assign reward points
    regards
    Venkata Devaraj

  • Converting Period to 1st and last date of that month

    Dear all,
    is there any FM to to do the following:-
    if in the selection screen i give the date as 09.2007 (MM.YYYY) then i want the output as
    01.09.2007 to 30.09.2007
    If u go to transaction MC.1  in that u will find this as select options.
    So when i enter in the selection screen the period from 09.2007 to 11.2007
    then the output should be 01.09.2007 to 30.11.2007. which i want to pass to MKPF table
    PLZ help

    hi rahul
    AT SELECTION-SCREEN.
      IF NOT p_abkrs1 IS INITIAL.
        IF NOT p_timr9 IS INITIAL.
          CALL FUNCTION 'PA03_PERIODDATES_GET'
            EXPORTING
              f_abkrs               = p_abkrs1
            IMPORTING
              f_permo               = wf_permo
              f_current_begda       = wf_begda
              f_current_endda       = wf_endda
            CHANGING
              f_current_period      = wf_pabrp
              f_current_year        = wf_pabrj
            EXCEPTIONS
              pcr_does_not_exist    = 1
              abkrs_does_not_exist  = 2
              period_does_not_exist = 3
              OTHERS                = 4.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
          p_begda = wf_begda.
          p_endda = wf_endda.
          p_ipabrp = wf_pabrp.
          p_ipabrj = wf_pabrj.
          IF NOT p_pabrp IS INITIAL OR NOT p_pabrj IS INITIAL.
            MESSAGE e016(rp) WITH 'Do not enter other period'.
            STOP.
            EXIT.
          ENDIF.
        ELSE.
          IF p_pabrp IS INITIAL OR p_pabrj IS INITIAL.
            MESSAGE e016(rp) WITH 'Enter a period'.
            STOP.
            EXIT.
          ENDIF.
          SELECT SINGLE * FROM t549a
                      INTO int_t549a
                      WHERE abkrs = p_abkrs1.
          IF sy-subrc = 0.
            SELECT SINGLE * FROM t549q INTO int_t549q
                                       WHERE permo = int_t549a-permo
                                         AND pabrj = p_pabrj
                                         AND pabrp = p_pabrp.
            IF sy-subrc = 0.
              p_begda  = int_t549q-begda.
              p_endda  = int_t549q-endda.
              p_ipabrp = p_pabrp.
              p_ipabrj = p_pabrj.
            ENDIF.
          ENDIF.
    reward points if useful
    karthik

  • TO FIND START DATE AND END DATE OF THE MONTH

    HAI ALL,
               I want to find the start of the date for the month and end of the date for the month, for given date.
    Ex. if input is : 08-06-2007,
                                           I want to get the first and last date for this month.
    . Is there any FM .
    thanks in advance,
    senthil kumar

    Hi,
    Use the Function modue RE_LAST_DAY_OF_MONTH to get the last day
    For first day..
    DATA: V_DATE TYPE D.
    V_DATE = SY-DATUM.
    V_DATE+6(2) = '01'.
    WRITE: / 'First day is ', v_date.
    Thanks,
    Naren

  • FM for First and Last Day_Current Month

    Hello All,
    Inorder to update the TVARV table, two new variables were needed which will get the First and Last Day of current month.
    One FM i was able to find was BKK_GET_MONTH_LASTDAY which takes the Todays date and outputs the Last date of the month. IS there any FM for FIRSTDAY Current month....
    Regs,
    -PSK

    Hi Sravan,
    Following help may help you.
    FM - BUILD_PERIOD_TABLE
    code is mentioned below.
    data: it_cperiod type table of range_prds with header line,
    define one variable as range like -
    ranges: r_cperiod for sy-datum,
    CALL FUNCTION 'BUILD_PERIOD_TABLE'
        EXPORTING
          YEAR         = <current year>
        TABLES
          PERIOD_TABLE = it_cperiod.
      read table it_cperiod with key per_id = <current month>
      refresh r_cperiod.
      r_cperiod-sign = 'I'.
      r_cperiod-option = 'BT'.
      r_cperiod-low = it_cperiod-begda.
      r_cperiod-high = it_cperiod-endda.
      append r_cperiod.
    Now, you can see begin and end of moth in r_cperiod.
    Regards,
    Parag

  • Get First and last day of Month..

    Hi Friends,
    I am trying to fetch First and Last day of a month and would like to implement that in the following code:
    SELECT COALESCE(Date_A, Date_B, Date_C)
    FROM dual
    Here Date A and B are in Format of MM DD YYYY (March 14, 2008)
    and Date C is like MM YYYY (March 2008)
    How can I get the Date_C as March 1, 2008 OR March 31, 2008 format if Date A and B are NULL ?
    Thanks!
    Edited by: user11095386 on Apr 23, 2009 10:45 AM

    Hi,
    In my earlier message, I thought that you were starting with strings like '03 12 2009' and that you wanted to display them as 'March 12 2009'. If what you have is just the reverse, then just reverse the format strings in my first message. Add a comma, if you want one, in the appropriate format string.
    I believe this is what you want:
    COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
             , TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
             , TO_CHAR ( TO_DATE ( Date_C, 'fmMonth YYYY'),    'MM DD YYYY')
             )Notice how, on the 3rd line, TO_DATE is called without DD in the format string:
    TO_DATE ( Date_C, 'fmMonth YYYY')When you do this, the day defaults to the 1st of the month, so this is all you have to do to convert the VARCHAR2 'March 2009' to the DATE 01-Mar-2009.
    If you want the last day of the month, not the first, when Date_C is chosen, then use LAST_DAY:
    COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
             , TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
             , TO_CHAR ( LAST_DAY ( TO_DATE ( Date_C
                                              , 'fmMonth YYYY'
                 , 'MM DD YYYY'
             )

Maybe you are looking for

  • Xml file error in file adapter

    Hi Experts. In my sceanrio i am Using File dapter. this adapter pick the Xml file. here my client provieded sample Xml file (this Xml file don't have the  Url and Xml version). I am getting mapping error. nothing is wrong with mapping. Client provede

  • BPEL and conversational services

    For some reason my earlier post failed. It threw up some weird error. I am building a BPEL which is composed of synchronous web services. The simplest of these business processes has a single synchronous web service call. The web service returns an a

  • IPhone Messages (SMS) app problem

    I've been having a problem with the Messages (SMS) app on my iPhone 3GS. As a matter of personal choice (or rather by nature since I'm slightly prone to OCD), I like to "close (or kill)" all my apps from the multitasking bar and have it stay nice and

  • To_char function not working

    hi, I want to get the max dates on format MM/DD/YYYY. the problem is it only works on select distinct t.id, max(to_char (t.tr_date,'MM/DD/YYYY')) as transaction_date, s.contract_date, max(i.start_date) as start_date, max(i.end_date) as end_date from

  • TS3274 Hi my ipad is frozen with an itunes icon in the middle and a plug symbol towards it and it is not letting me do anything!!! Help

    Not sure what is happening, and not very techy! so please any advice!