First day of current month, one year ago

All,
Does anyone have a calculation or know how I can calculate the first day of the current month, one year ago? I am trying to setup a filter criteria to show all records created >= 1st day of current month for prior year and <= the last day of the prior month. I have the second half of the equation for last day prior month but need some help on the first half.
Thanks in advance for any pointers!
D

You can try:
SELECT TRUNC(ADD_MONTHS(sysdate, -12), 'MON') FROM dual;
Or
SELECT TRUNC(sysdate-NUMTOYMINTERVAL(1,'YEAR'), 'MON') FROM dual;

Similar Messages

  • Function to find the Last Date of Month One Year Ago - RETURNS ERROR

    I've written sql code which takes a date and finds the Last Day of the Month one year ago. For example,  it takes the date '2015-04-17' and returns the date '2014-04-30'. The code works fine in a query. Now I'm trying to turn this into a function. However,
    when I try to create the function I get the error:
    Operand type clash: date is incompatible with int
    Why is this error being returned?
    Here is my function:
    CREATE FUNCTION dbo.zEOM_LY_D(@Input Date)
           RETURNS date
    AS
    BEGIN;
      DECLARE @Result date;
      SET @Result =  convert(DATE, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,dateadd(m, -11, @Input)+1),0)),101)
        RETURN @Result;
    END;
    Thanks for any help you can give.
                     

    Stan,
    Thanks very much- that does the trick. I should have said I am using SQL 2008 so EOMONTH is not available to me. I still don't get why I got an error though, since I was treating a date like a date and not like an int.
    Thanks, John
    I think i found the issue but i do not know why it is causing the issue. i think may be the way dates are treated/stored internally..i think dates are stored as no of days after 0001/01/01 but cannot see how this cwould effect..may be somebody else can through
    some light..... 
    if you make it as datetime it will work,
    if you leave it as date - eliminate adding 1...  you should prefer to use dateadd to add/substract dates.
    try this to understand..
    --removed the +1 in the code
    declare @input date
    set @input ='20150503'
    select
    convert(DATE, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,dateadd(m, -11, @Input)),0)),101)
    go
    --made the datatype as datetime
    declare @input datetime
    set @input ='20150503'
    select
    convert(DATE, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,dateadd(m, -11, @Input)+1),0)),101)
    Hope it Helps!!

  • Date for first day of current month

    How can i get the date for first day of current month ?

    select trunc(sysdate,'MM'),to_char(trunc(sysdate,'MM'),'DD'),to_char(trunc(sysdate,'MM'),'Day') from dual;

  • How to get the first day of current month

    hi guys,
    i am trying to get the first day of current month which get from the date i input at the selection screen. my method is not so good, so i was wondering if there is better way to get the this,
    thanks.

    Try this .
    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.
    Cheers

  • First Day of Current Month

    I need to return the first day of the current month. I have read I can use:
    WITH  MEMBER [Measures].[FirstDayOfMonth] AS 
    DateSerial(Year(Now()), Month(Now()), 1)
    However, this returns an incorrect format. Can this date member be formatted to yyyy-MM-dd?
    I have also read I can use OpeningPeriod but I could not get this to work.
    My date Hierarchy is:
    [Date].[Year Month Day].[Month]
    And my month members are in the yyy-MM-dd format, for example:
    [Date].[Year Month Day].[Month].&[2015-02-01]

    Thanks Richard,
    I am not sure what the "aa" string is for?
    Yes, I can get the current date using:
    WITH
    MEMBER [Measures].[Month Day] AS
    FORMAT(Now(), "yyyy-MM-dd")
    But I need to return the first date of the current month dynamically. For example, today this value would be: 
    [Date].[Year Month Day].[Month].&[2015-02-01]
    So I cannot use Parent or FirstChild as the hierarchy will not recognise the
    FORMAT(Now(), "yyyy-MM-dd") as a month member as it returns 2015-02-18.
    I believe I need to extract the current month day value, subtract this value from the Now() and add 1 (start of month), for example:
    StrToMember("[Date].[Year Month Day].[Month ].&[" + FORMAT(Now()-[Month Day]+1,
    "yyyy-MM-dd") +"]")
    Which will be 2015-02-18 - 18 + 1 = 2015-02-01
    Or:
    WITH
    MEMBER [Measures].[Month Day] AS
    FORMAT(Now()-[Month Day Value]+1, "yyyy-MM-dd")
    SET [FirstOfMonth] AS
    StrToMember("[Date].[Year Month Day].[Month].&[" + [Measures].[Month Day] +"]")
    So I need a new member to return the month day value.
    Does this make sense? Is there a better way to do this?

  • Last day of previous month, first day of current month

    Hi,
    Whats the best way to calculate the last date of the previous month, and the first day of the current month.
    Thank you for your help.
    Sumit.

    Here are FMs
    SG_PS_GET_LAST_DAY_OF_MONTH    FM calculating the last day of a month                                                                               
    FVOZ                                                                               
    RE_LAST_DAY_OF_MONTH                                                                               
    HRHCP00_TIME_HANDLING                                                                               
    HR_HCP_GET_LAST_DAY_OF_MONTH                                                                               
    HRVE_REPORTING                                                                               
    HRVE_LAST_DAY_OF_MONTH                                                                               
    RPDD                           HR-D: Payroll Germany                                              
    RP_LAST_DAY_OF_MONTHS          HR-D: Determine last day of month                                                                               
    SLS0                           PAW - Miscelaneous (MISC)                                          
    SLS_MISC_GET_LAST_DAY_OF_MONTH FM calculating the last day of a month                                                                               
    VVSRCH                                                                               
    LAST_DAY_OF_MONTHS                                                                               
    BWSO_DATE_GET_FIRST_WEEKDAY     
    CKSO                            
    CK_F_GET_FIRST_DAY_OF_DATE      
    HRBEN00SPENDA                   
    HR_BEN_SPENDA_FIRST_LAST_DAY    
    HRPB                            
    HRPP_CCODE_GET_FIRSTDAY_PERIOD  
    HRVE_PAYROLL                    
    HRVE_GET_FIRST_LAST_MONDAY      
    JBT6                            
    ISB_GET_FIRST_DAY               
    KED2                            
    RKE_GET_FIRST_DAY_IN_PERIOD     
    MCP2                            
    MC_PERIOTAB_BT_FIRST_LASTDAY    
    MC_PERIO_GET_FIRST_AND_LASTDAY  
    Thanks
    SK

  • SQL select Statement -first day and last day of the month - 1 year from now

    Hi,
    I need to write a SQL to get the dates in between first day and last day of the month one year from now.
    SELECT last_day(add_months(sysdate,12)) as lastday from dual
    What could be the Query to get the first day of the month one year from now..
    ie ..Sysdate - 3-DEC-2009
    Result - 1-DEC-2010
    thank you

    Hi,
    You can use TRUNC with 2 arguments to get the first DATE in a month, year, quarter, week, hour, minute, ISO year, ...
    SELECT  TRUNC ( ADD_MONTHS ( SYSDATE
                               , 12
                  , 'MONTH'
                  )     AS first_of_month
    FROM    dual
    ;The DATE returned will be in the same month, year, quearter, ... as the first argument.
    \We convered the last day of the month in [your previous question|http://forums.oracle.com/forums/message.jspa?messageID=3942939#3942939].
    At that time, I warded about using LAST_DAY as a cutoff point; TRUNC is a much better way.
    For example, to find all appointment_dates in the current month next year:
    SELECT  *
    FROM    appointments
    WHERE   appointment_date >= TRUNC (ADD_MONTHS (SYSDATE, 12), 'MONTH')
    AND     appointment_date <  TRUNC (ADD_MONTHS (SYSDATE, 13), 'MONTH')Note that
    the first part of the WHERE clause calls for dates on or equal to the beginning of the 12th month in the future, but
    the second part of the WHERE clause calls for dates before, not equal to , the beginning of the 13th month in the future.

  • Date Functions( first day of a month that is 3 months from now....)

    I have recently written my first stored procedure.
    Its rather a bunch of SQL statements.
    I had to hard code lot of dates. most of them are first day of the current monthe or last day of current month etc.
    I thot of parametrizing all the dates, but if a business person has to include all the parameters they could go wrong and get the wrong results.
    Now, I want to use date functions to achieve these requirements:
    Can any one please throw some insght into this:....
    1) First day of current month,
    2) last day of current month.
    3) first day of previious month
    4) last day of previous month
    5) first day of a month that is 3 months from now.
    6) last day of a month that is 3 months from now.
    7).....
    Can any one please throw some light on any one of this.. I can try to work from there onwards ....
    Thanks a lot in advance,
    Ac

    Hi there,
    1) First day of current month
    select trunc(sysdate, 'MM') from dual;
    2) last day of current month.
    select trunc(add_months(sysdate, 1), 'MM') - 1 from dual;
    3) first day of previious month
    select trunc(add_months(sysdate, -1), 'MM') from dual;
    4) last day of previous month
    select trunc(sysdate, 'MM') - 1 from dual;
    5) first day of a month that is 3 months from now.
    select trunc(add_months(sysdate, 3), 'MM') from dual;
    6) last day of a month that is 3 months from now.
    select trunc(add_months(sysdate, 4), 'MM') - 1 from dual;cheers,
    Anthony

  • Need sql querry for records between Current Year First day and Current Day

    Hi,
    I have a table like this...
    Empid     Empname     DOJ
    TEST1     ERDDF     19-Jun-2011
    TEST2     AA     22-Mar-2011
    TEST3     SS     22-Oct-2011
    TEST4     VV     01-Jan-2012
    TEST5     HH     01-Apr-2012
    TEST6     AS     18-Jun-2012
    TEST7     ER     26-Jun-2012
    TEST8     ERDDF     28-Jun-2012
    My output like this...
    Empid     Empname     DOJ
    TEST4     VV     01-Jan-2012
    TEST5     HH     01-Apr-2012
    TEST6     AS     18-Jun-2012
    TEST7     ER     26-Jun-2012
    Logic:
    records between Current Year First day and Current Day(sysdate)

    937506 wrote:
    Hi,
    I have a table like this...
    Empid     Empname     DOJ
    TEST1     ERDDF     19-Jun-2011
    TEST2     AA     22-Mar-2011
    TEST3     SS     22-Oct-2011
    TEST4     VV     01-Jan-2012
    TEST5     HH     01-Apr-2012
    TEST6     AS     18-Jun-2012
    TEST7     ER     26-Jun-2012
    TEST8     ERDDF     28-Jun-2012
    My output like this...
    Empid     Empname     DOJ
    TEST4     VV     01-Jan-2012
    TEST5     HH     01-Apr-2012
    TEST6     AS     18-Jun-2012
    TEST7     ER     26-Jun-2012
    Logic:
    records between Current Year First day and Current Day(sysdate)Probably you are looking for :
    where DOJ between trunc(sysdate,'YYYY') and sysdateRead {message:id=9360002} and always provide details mentioned in this thread.

  • Function Modules to get First day of week, month, Year

    Can anyone name the Function Modules for getting First day of week, month ,year.

    to get first day of week use this function;   WEEK_GET_FIRST_DAY
          CALL FUNCTION 'WEEK_GET_FIRST_DAY'
               EXPORTING
                    WEEK         = '201107'
               IMPORTING
                    DATE         = l_date
               EXCEPTIONS
                    WEEK_INVALID = 1
                    OTHERS       = 2.
    with DATE_COMPUTE_DAY function you can get date number in week.
    CALL FUNCTION 'DATE_COMPUTE_DAY'
           EXPORTING
                DATE = workdate
           IMPORTING
                DAY  = day_of_week_num
           EXCEPTIONS
                OTHERS  = 8.
      CASE day_of_week_num.
        WHEN 1.
          hold_day_of_week = 'Monday'.
        WHEN 2.
          hold_day_of_week = 'Tuesday'.
        WHEN 3.
          hold_day_of_week = 'Wednesday'.
        WHEN 4.
          hold_day_of_week = 'Thursday'.
        WHEN 5.
          hold_day_of_week = 'Friday'.
        WHEN 6.
          hold_day_of_week = 'Saturday'.
        WHEN 7.
          hold_day_of_week = 'Sunday'.
        WHEN OTHERS.
          hold_day_of_week = 'invalid'.
      ENDCASE.

  • Can I view history from one year ago?

    I'm trying to find out what sites I was on one year ago but the history only keeps track up to 6 months. Is there any way to retrieve history from a year ago?

    No, if history is only kept for 6 ,months then older history is no longer available.<br />
    The default in Firefox 3 versions is to keep history for 180 days (6 months).<br />
    * http://kb.mozillazine.org/browser.history_expire_days
    In Firefox 4+ that has changed to a maximum number of pages that is kept.<br />
    So you can update to Firefox 8 and it will remember more history, but you can't get back older history.<br />
    <br />
    There is no time limit in Firefox 4+ versions for the history.<br />
    Firefox determines automatically how many pages can be kept without affecting the performance.<br />
    You can see the current value via the reads-only pref places.history.expiration.transient_max_pages on the about:config page.
    See:
    * http://blog.bonardo.net/2010/01/20/places-got-async-expiration

  • First day of previous month

    Hi,
    I created a data parameter and I want my date parameter default value to be the first day of previous month, the expression {$FIRST_DAY_OF_MONTH()$} is pointing to the fitst day of current month and when I tried {$FIRST_DAY_OF_MONTH()-1$} it is just subtracting a day(thought to go back one month)...Is there way I can point my default value to first day of previous month.?
    Regards

    hmm is BI Publisher in Beta? Are there any workarounds you can suggest me to achieve this?
    I see the user stated that a workaround is possible at RTF template level? How can we achieve this?
    Re: Default date as first of month
    Edited by: user8937215 on Aug 10, 2010 7:30 AM

  • HT201238 My account was not automatically upgraded to an new annual plan, I got it one year ago and I got a message saying my Icloud storage was full and I that I only had 5gb free. What can I do ?

    My account was not automatically upgraded to an new annual plan, I got it one year ago and I got a message saying my Icloud storage was full and I that I only had 5gb free. What can I do ?

    Thanks Winston, thats the first thing I wanted to do but I dont see any Annual Plan (like I had), only monthly plans, and they said that as I got a Storage Plan before September 2014 I would be "automatically" updgraded to a new annual plan with reduced pricing. Dont know how I can get it now.

  • Album that show photos from one year ago today

    I want to be able to create an Album that shows pictures from exactly one year ago to the current date. It would be auto updating.
    any idea if this is possible?

    Set it so that the date is in the last 365 days and the date isn't in the last 364 days. This will show photos from exactly 365 days ago.
    (42039)

  • First day of next month

    Hi,
    My requirement is to display the first day of next month when a month and year are selected in the dashboard prompt. .
    I have 2 prompts, one for Month and the other for Year.
    For example if an user selects 2012 for Year and 09(September) for Month, my column in the report should display 10/1/2012
    Please help in getting this logic working.
    I am using OBIEE 10.1.3

    Use min(date), this always return first day of selected Year,month
    Then add a month to this date.
    Or else get the date of the month and use at DATE
    TIMESTAMPADD(SQL_TSI_MONTH, 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( DATE) * -(1) + 1, DATE))
    Pls mark as correct/helpful if helps
    Appreciate if you update your other post with helpful/correct
    Edited by: veeravalli on Oct 2, 2012 11:53 AM

Maybe you are looking for