Finding first day of months past

I know how to find the first of the current month.
today =03/04/2011 MM/DD/YY
SELECT TO_CHARTRUNC(SYSDATE,'MM', 'DD-MON-YYYY') FROM dual;
3/1/2011
Is there an easy way to find the first day of lets say 2 months ago?
2/1/2011
Secondly, how can I pad the output of monty and day withn zero's ie 02/01/2011
Thanks to all who answer

Hi,
You can do it like this,
SQL> SELECT TRUNC(ADD_MONTHS(SYSDATE,-2),'MM') dt FROM dual;
DT
01-JAN-11
With Zeroes,
SQL>
SQL> SELECT TO_CHAR(TRUNC(add_months(SYSDATE,-2),'MM') , 'MM/DD/YYYY') dt FROM dual;
DT
01/01/2011
SQL> G.
Edited by: G. on Mar 4, 2011 2:41 PM
Over looked 2 months.

Similar Messages

  • Basic Ask :  Search First Day of month two months ago

    Hi
    How can I to find first day ('01) of two months ago ?

    SQL> select last_day(add_months(sysdate,-3)) + 1 from dual;
    LAST_DAY(AD
    01-FEB-2007Message was edited by:
    Eric H
    Jens has a better solution. Ignore mine.

  • Default value of date as first day of month

    Ho can I make my default value of date parameter as first day of month? {$SYSDATE()$} gives only current date and we can make it like {$SYSDATE()-7$} if we want to minus 7 days but how can we set the default value to first day of month?

    I got the answer...It is {$FIRST_DAY_OF_MONTH()$} instead of {$SYSDATE()$}

  • First Day of Month - CR 2008

    Hi experts,
    What's the code of First Day of Month?
    For example, AsOfDate : 10/29/2011, I want to get 10/01/2011 from 10/29/2011. I made it like follow, but I believe there is a simple code.
    CDate(ToText(DATEPART("m", ),0,'') + '/1/' + ToText(DATEPART("yyyy", ),0,''))
    Thanks,
    David

    Hi
    Try the follwoing :
    currentdate - day(currentdate)+1
    Note : replace currentdate with your date field.
    Thanks,
    Sastry

  • Find first day of any year

    How to find first day of any year using sql? Is there any function for it ?

    Using below SQL you have to just pass the year:
    SQL> select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual;
    Enter value for tyear: 2000
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||2000, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    Saturday
    SQL> /
    Enter value for tyear: 2001
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||2001, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    Monday
    SQL> /
    Enter value for tyear: 1990
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||1990, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    MondayRegards

  • Need sql querry for  PreviousYear First Day Same Month And Currentday rec

    Hi ,
    I hAVE TABLE FOR EXAMPLE,
    emp sal Arrivaldate
    111 200 03-mar-2011
    100 200 03-mar-2008
    150 200 06-mar-2012
    170 200 03-mar-2003
    178 200 03-mar-2004
    112 200 12-jun-2012-------------------->For Example THIS IS TABLE WE HAVE LOT OF RECORDS
    I need querry to get based on this condition:Arrival Date is between Previous Year First Day Same Month And Current day.
    Any one help me on this.....

    Hi,
    To get the records between Previous Year First Day Same month to Current day..
    SELECT TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM') AS last_yr_first_date, TRUNC(SYSDATE) AS PRESENT_DATE
      FROM DUAL;Which Outputs to:
    LAST_YR_FIRST_DATE     PRESENT_DATE
    6/1/2011                   6/13/2012When you give TRUNC(sysdate) It will removes the Time part of the SYSDATE.
    For Ex :
    TRUNC(SYSDATE) means that is 6/13/2012 which doesn't give the time part in the query.
    Which takes into account the day start that is from 12:00 A.M to today midnight 11.59 P.M.
    And, One thing is that
    emp sal Arrivaldate
    111 200 03-mar-2011
    100 200 03-mar-2008
    150 200 06-mar-2012
    170 200 03-mar-2003
    178 200 03-mar-2004
    112 200 12-jun-2012The arrivaldate is in Character format so you need to convert to date type as
    SELECT TO_DATE(ARRIVALDATE,'DD-MON-YYYY') from your_table;
    and the comparison can be done as
    SELECT *
      FROM YOUR_TABLE
    WHERE TO_DATE (ARRIVALDATE, 'DD-MON-YYYY')
       AND TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM')
       AND TRUNC (SYSDATE);Good day!!!!!!!!!!!!!!!!!!!!!!!!
    Thanks,
    Shankar

  • 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.

  • Events over multiple days only show on the first day in 'Month' view

    Hi,
    I've noticed that if I create an event that spans over two days (for example 23 May 2008 at 6 PM to 24 May 2008 at 1 PM) are only displayed on the from date in Month view.
    This is unfortunate because if I look at my calendar in Month view, I think I'm free on the 24th, when in fact I'm busy until 1 PM.
    Is there a way to get the Month view to display an entry for the event on both days (other than creating one event running from 23 May 2008 at 6 PM to 11:59 PM and a second from 24 May 2008 at 1:01 AM to 1 PM)?
    Message was edited by: Sam Watterson

    Hi Sam
    I just had the exact same problem the other day. I was asked to make an appointment with someone, I checked my calendar (actually on my iPhone) and I looked available that day so agreed and even entered the event. Turns out I will be working 70 miles away on the event I entered on the day prior. I've had the embarrassment of having to reschedule - makes me look disorganised.
    The month view on iPhone is just the same as iCal - if it's not an 'all day' event it only shows on the first day. This is poor. I recall even outlook and windows mobile calendar manages to display this sensibly. Apple should be fixing this pronto.

  • "morse code" iCal - first day of month not showing

    on the first square of the calendar (whether it's the first day of the current month or the last day of the previous month) the event titles will not show up - all that shows are dots and dashes and, in some months, solid lines. When you click on one of these events, the event details do show up on the pull-out event details sidebar. This is funky, any way to fix it?

    kduballstar,
    Very often display anomalies can be rectified by refreshing your iCal plist file. This can be accomplished by quitting iCal and dragging the com.apple.iCal.plist file which is located in your Macintosh HD/Users/yourusername/Library/Preferences Folder to the Desktop. Then log out/in or restart and check iCal for normal behavior. You can delete the iCal plist file on your Desktop.
    Let us know what happens.
    ;~)

  • Current date, first day of month, last day of month, current week, current

    Hi All,
    may be the question will sounds basic for your guys, I am connecting via MDX a cognos reportnet on a BW 3.0B..due to loads of limitations on filtering via MDX on 'business date/time functions' , I would need to create in the infoqueries that are my data sources, the following additionnal objects:
    - current date
    - first day of current month
    - last day of current month
    - current week
    - current year
    I do not want prefiltered infoqueiries but object with these single values so that from reportnet I can have something like: OCALDAY between 'first day of current month' and 'last day of curent month'
    Is there standard fonction for this under BW/BEX or if we need to developp functions has nayone some code examples.
    thanks a lot for your great input
    David

    Hi,
    In universe level if you want implement the requirede functions then you have to write custom sql and if you want to implement them in Reporting level then most of the functions are available to you. e.g. Quarter,Month, Year, Current Date....
    Cheers,
    Suresh A.

  • First day of month

    I Have a date . I want first day of that month.
    Please give me FM or coding
    reg
    vvv

    Hi,
    Use below FMs:
    First day and last day of month:
    HR_JP_MONTH_BEGIN_END_DATE
    First and Last day in year
    FIRST_AND_LAST_DAY_IN_YEAR_GET
    DATA:DATE1 TYPE D.
    DATA:DATE2 TYPE D.
    CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
      EXPORTING
        I_GJAHR        = SY-DATUM+0(4)
        I_PERIV        = '24'
      IMPORTING
        E_FIRST_DAY    = DATE1
        E_LAST_DAY     = DATE2
      EXCEPTIONS
        INPUT_FALSE    = 1
        T009_NOTFOUND  = 2
        T009B_NOTFOUND = 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.
    WRITE: 'First Day', DATE1, 'Last day' , DATE2.
    Also check
    CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
        EXPORTING
        i_gjahr              = sp_gjahr
        i_monmit             = gp_monat
          i_periv              = 'K4'
          i_poper              = sp_monat
    IMPORTING
         e_date               = gv_firstday
    EXCEPTIONS
       input_false          = 1
       t009_notfound        = 2
       t009b_notfound       = 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.
    Regards,
    Raj.

  • First day in month

    Hi,
    i need fm that bring the first day of next month,
    lif i put 01052008 i get 01062008
    or 15022007 get 01032007.
    Regards

    Hi,
    For Year
    Use FM: FIRST_AND_LAST_DAY_IN_YEAR_GET
    DATA:DATE1 TYPE D.
    DATA:DATE2 TYPE D.
    CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
      EXPORTING
        I_GJAHR        = SY-DATUM+0(4)
        I_PERIV        = '24'
      IMPORTING
        E_FIRST_DAY    = DATE1
        E_LAST_DAY     = DATE2
      EXCEPTIONS
        INPUT_FALSE    = 1
        T009_NOTFOUND  = 2
        T009B_NOTFOUND = 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.
    WRITE: 'First Day', DATE1, 'Last day' , DATE2.

  • Show first day of month

    The jquery datepicker is being used to select dates. Is there a way to only show the first day of the month when the date selected is made?
    Este

    ok
    Use SQL Function FIRST_DAY
    SELECT FIRST_DAY(your_date) FROM dual;
    or
    use this packge
    CREATE OR REPLACE FUNCTION fday_ofmonth(value_in DATE)
    RETURN DATE IS
    vMo VARCHAR2(2);
    vYr VARCHAR2(4);
    BEGIN
    vMo := TO_CHAR(value_in, 'MM');
    vYr := TO_CHAR(value_in, 'YYYY');
    RETURN TO_DATE(vMo || '-01-' || vYr, 'MM-DD-YYYY');
    EXCEPTION
    WHEN OTHERS THEN
    RETURN TO_DATE('01-01-1900', 'MM-DD-YYYY');
    END fday_ofmonth;
    Edited by: BelMan on Sep 18, 2010 2:26 PM
    Edited by: BelMan on Sep 18, 2010 2:27 PM

  • Find first day of open posting period

    Hi all experts,
    my problem:
    I neded to find the first day of the open posting period in my report.
    You know any FM or other?
    thank you all, points for all.

    Hi..
    Try the FM
    <b>G_POSTING_DATE_OF_PERIOD_GET</b>
    If not:
    Check the Function modules in the Same Function group GUPD.
    <b>Reward if Helpful</b>

  • I want first day of month any function module is their

    hi i want a function module in that it should return the first day of that month .
    for example if i enter 15.12.2007 it should return 01.12.2007 or 13.06.2007 it should return 01.06.2007

    ähm why would you need a FM for that?
    you probably have a variable whicghs stores your date.
    data:  lv_date    type dats value,
             lv_date2   type dats.
    data: lv_swap    type c length 10.
    concatenate '01' lv_date+2 into lv_swap.
    lv_date2 = lv_swap.
    write lv_date2.

Maybe you are looking for

  • SMD tasks queued

    Dear all. Since two months ago we have EWA for our java portal running succesfully. Now, suddenly, the report shows only a few information. We have seen in scheduler that all the tasks are always in status 'queued' and they don't run. We have followe

  • Get content from html page

    Hey guys, Im looking at accessing a webpage, downloading the content then stripping out the parts i want. http://sunsolve.sun.com/search/document.do?assetkey=1-34-9-1 For example, I would like to be left with just the patches and their information, n

  • Install Problems for PSE8

    Our small business recently bought PSE8 for windows.  We attempted to install on the first office computer, when the serial # was inputed, it gave an error saying that it was an invalid serial number.  Called the company and found out we needed to un

  • I tried to install the latest version of iTunes on my Dell laptop but go this message: the program can't start because MSVCR 80.d11 is missing from you computer.   Help!

    I tried to install the latest version of iTunes on my Dell laptop but go this message: the program can't start because MSVCR 80.d11 is missing from you computer.   Help!

  • Invoice Cancellation done through ERS?

    Hi all, I need to cancel the invoice which is generated by ERS (MRRL Transaction). How can i cancel the invoice. Here is how i proceed, please let me know if its wrong. 1. Cancel the GR  (Is it necessary that i should cancel the GR or can i do return