Get month and year from date type

Hi all,
I need to get the month and year from the date type.
For example select to_date('2011-01-17', 'yyyy-mm-dd') from dual;Result needed:
01-2011Any ideas?
thanks in advance,
Bahchevanov.

Hello Bahchevanov,
if you need the date to compute something, then you can
TRUNC(SYSDATE,'mm')This will give you a date with the days removed -> 01.01.2011
Regards
Marcus

Similar Messages

  • Getting Day, month and year from Date object

    hello everybody,
    Date mydate = Resultset.getDate(indexField);
    Now i would like to get day, month and year from mydate.
    In another words, i'm looking for something equivalent to
    mydate.getDay() as this method is deprecated.
    Can somebody help me out please?
    Thank you in advance,

    swvc2000,
    Here is a sample class that demonstrates two ways in which to do this.import java.util.*;
    import java.text.*;
    public class DateSplitter {
       public static void main(String args[]) {
          /* even though your date is from a result set,
             pretend the following date is your date that
             you are using. The try catch block is used
             because I hand-crafted my date using
             SimpleDateFormat.  Substitute your date.*/
          Date yourDate = null;
          try {
             SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
             yourDate = formatter.parse("05/06/2000");
          } catch (ParseException e) { }
          //the following gets the current date
          Calendar c = Calendar.getInstance();
          //use the calendar object to set it to your date
          c.setTime(yourDate);
          //note months start at zero
          int month = c.get(Calendar.MONTH);
          int year = c.get(Calendar.YEAR);
          int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
          System.out.println("Calendar Month: "+month);
          System.out.println("Calendar Day: "+dayOfMonth);
          System.out.println("Calendar Year: "+year);
          System.out.println();
          /* Simple date format can also be used to strip them
             out of your date object.  When you use it, notice that
             months start at 1.  Also, it returns string values.  If
             you need integer values, you will have to use
             Integer.parseInt() as I did below.  If you are
             only concerned about the string values, just remove
             the Integer.parseInt part. */
          DateFormat formatter = new SimpleDateFormat("M");
          month = Integer.parseInt(formatter.format(yourDate));
          System.out.println("SDF Month: "+ month);
          formatter = new SimpleDateFormat("d");
          dayOfMonth = Integer.parseInt(formatter.format(yourDate));
          System.out.println("SDF Day: "+ dayOfMonth);
          formatter = new SimpleDateFormat("yyyy");
          year = Integer.parseInt(formatter.format(yourDate));
          System.out.println("SDF Year: "+ year);
       }//end main
    }//end DateSplitter classtajenkins

  • Max month and year from table

    Hi,
    I have requirement to get max month and year from a table.
    DESC WHR_REPORT
    REPORTMONTH   NUMBER(2)
    REPORTYEAR    NUMBER(4)
    Sample data in table
    reportmonth    reportyear
    01              2009
    02              2009
    03              2009
    04              2009
    09              2009
    12              2009
    01              2010
    02              2010how do i get the max date which means 022010 from the table?
    thanks
    sandy

    Give this a shot:
    SQL> WITH whr_report AS
      2  (
      3         SELECT 01 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      4         SELECT 02 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      5         SELECT 03 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      6         SELECT 04 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      7         SELECT 09 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      8         SELECT 12 AS reportmonth, 2009 AS reportyear FROM DUAL UNION ALL
      9         SELECT 01 AS reportmonth, 2010 AS reportyear FROM DUAL UNION ALL
    10         SELECT 02 AS reportmonth, 2010 AS reportyear FROM DUAL
    11  )
    12  -- END SAMPLE DATA
    13  SELECT  MAX
    14          (
    15            TO_DATE
    16            (
    17              LPAD
    18              ( reportmonth
    19              , 2
    20              , '0'
    21              ) || reportyear
    22            , 'MMYYYY'
    23            )
    24          ) AS MAX_DT
    25  FROM    whr_report
    26  /
    MAX_DT
    02/01/2010 00:00:00This is a case where you should use the correct data types to store data. These two column should be ONE column with a data type of DATE.

  • Is there a way to change the date format so that delegates have to choose a day, month and year from a drop down menu as my delegates keep forgetting to change the year of their information

    When my delegates are filling in a event form i have put together, a large number of them forget to change either the month or year on the date field. Is there a way to have a date field that has drop down boxes for day, month and year so they have to choose rather than a date been already on the screen??
    Thanks

    Hi Christopher,
    The WEEKDAY function allows specifying either Sunday or Monday as the first day of the week:
    WEEKDAY
    The WEEKDAY function returns a number that is the day of the week for a given date. WEEKDAY(date, first-day)
      date:  The date the function should use. date is a date/time value. The time portion is ignored by this function.
      first-day: An optional value that specifies how days are numbered.
    Sunday is 1 (1 or omitted):  Sunday is the first day (day 1) of the week and Saturday is day 7.
    Monday is 1 (2):  Monday is the first day (day 1) of the week and Sunday is day 7. Monday is 0 (3):  Monday is the first day (day 0) of the week and Sunday is day 6.
    But I think you are referring to the first day of the 'workweek', for which I do not see a means of defining a custom value.
    Since you want to 'insert categories', though, you could easily define your own, using WEEKDAY(date) or WEEKDAY(date,1), plus an IF statement to return the category label appropriate to the day. Here's one for a Sunday to Thursday work week. Dates are in column A, the formula is in whichever column you want as the Category column. For the example, I've placed it in column B.
    B2, and filled down: =IF(WEEKDAY(A)<6,"Work","Off")
    The top table shows the weekday numbers returned for each day of the week for each of the three permitted values for the optional second argument. The bottom table shows the results from the formula above, used to define a category label for each date:
    A10 was left blank intentionally, to determine if the lack of data resulted in an error. The Warning message, flagged by the blue 'warning' triangle, is "The formula uses a number in place of a date." The 'date' assigned to this numerical value of zero was a Friday, but I'm not certain when. Probably best to avoid extra rows with no date shown.
    Regards,
    Barry

  • Function module for getting month and year of the previous month (say -6)

    Hi,
    Is there a function module that will get you the month and year of say, a month before, and as far as 11 months ago.
    For example, say today is 6/2007. I want 7 months ago.
    How do i get this value?
    What function module or method is available?
    Points will be rewarded and responses will be appreciated.
    Thank You,
    John

    Hi
    lv_period gives the month and year which is two months earlier now as we have specified lv_months as -2.
        DATA: LV_PERIOD LIKE S001-SPMON,
              LV_MONTHS(2) TYPE C VALUE '2-',
              LV_DATUM LIKE SY-DATUM,
              LV_NEWDT LIKE SY-DATUM,
            P_SPMON LIKE S001-SPMON VALUE '200601'.
        CONCATENATE P_SPMON '01' INTO LV_DATUM.
        LV_PERIOD = P_SPMON+0(6).
        CALL FUNCTION 'MONTH_PLUS_DETERMINE'
             EXPORTING
                  MONTHS  = LV_MONTHS
                  OLDDATE = LV_DATUM
            IMPORTING
                 NEWDATE = LV_NEWDT
             EXCEPTIONS
                  OTHERS  = 1.
         IF SY-SUBRC = 0.
           LV_PERIOD = LV_NEWDT+0(6).
         ENDIF.
    WRITE :/ LV_PERIOD.
    OR
    Use the following FM for getting the year and the month based on date
    CACS_DATE_GET_YEAR_MONTH
    or
    Call Function 'CCM_GO_BACK_MONTHS '.
    Funny module: 03/31/2002 - 1 month = 02/31/2002
    OR
    RE_ADD_MONTH_TO_DATE ( Add / substract month to/from date )
    Need ur reward points.
    Best regards,
    Ravi

  • Any F.Module is there to get  'Month and day '  from the given input number

    Hi experts,
        I am working on Inventory withdrawl report and in the selection screen, If i enter the CHARG (Batch number) then  I need to display the posting date by default in the next selection input based on the Batch number.
    In the selection screen :
    Batch : 7111WF0211.
    Posting Date :  (I need to display by default based on batch number).
    My requirement is,  in the above Batch first digit '7' is the year.
    And  from 2nd to 4th digit. i.e., 111. I need to find out month and day from 111.
    I mean from  1 to 365 days, In which day and which month '111' will come ?
    Please send me the code or suitable Function Module. Your help will be appreciated.
    Thanks,
    Ranji.

    Use FM ADD_TIME_TO_DATE
    Do this
    days = batch+1(3).
    days = days - 1.
    Call Function 'ADD_TIME_TO_DATE'
    exporting
    i_idate = '01.01.2008'
    i_time = days
    i_iprkz = 'D'
    importing
    o_idate = date_p_d
    You will get the date in date_p_d.
    But what about Leap years? IS the first number the year?
    IF so pass in i_idate the first of january of that year so you get the correct day depending if it is a leap year or not
    Edited by: Ramiro Escamilla on Feb 26, 2008 9:56 PM

  • Loop through month and year till date while using a merge statement

    Hello Guys,
    I have 2 tables with the following datas in them:-
    Company
    CompanyId CompanyName
    1                 Company1
    2                 Company2
    3                 Company3
    Employees
    EmployeeId EmployeeName CompanyId StartDate
    1                  Employee1        1                 12/21/2011
    2                  Employee2        1                 01/20/2012
    3                  Employee3        2                 03/23/2012
    4                  Employee4        2                 07/15/2012
    5                  Employee5        2                 01/20/2013
    6                  Employee6        3                 12/17/2013
    Now i want to check, How many people were recruited in the team in the specified month and year? I have the storage table as follows:-
    RecruiterIndicator
    CompanyId Year Month EmployeeRecruited
    1                 2011 12      1
    1                 2012 1        1
    2                 2012 3        1
    2                 2012 7        1
    2                 2013 1        1
    3                 2013 12      1
    This should be a merge stored procedure that should update the data if it is present for the same month year and company and insert if that is not present?
    Please help me with this
    Thanks
    Abhishek

    It's not really clear where the merge to come into play. To get the RecruiterIndicator table from Employess, this query should do:
    SELECT CompanyId, Year(StartDate), Month(StartDate), COUNT(*)
    FROM   Employees
    GROUP  BY CompanyId, Year(StartDate), Month(StartDate)
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Fetching month and year from CV of Time dim

    Hi,
    I am working on BPC 7 MS version, SP3. I need to fetch Month and Year values from my Current View (i.e., %TIME_SET%) .... and if the month is AUG and year is Current I then want a logic to run... Is this possible??
    I have written the following code, and only if i hardcode the time (WHEN TIME IS 2009.AUG) the logic seems to work. But I want it to be dynamic
    *XDIM_MEMBERSET ACCOUNT=INC_REC_IN_AD
    *XDIM_MEMBERSET TIME=%YEAR%.AUG,%TIME_SET%
    *XDIM_MEMBERSET CATEGORY=ACTUAL
    *WHEN ACCOUNT
    *IS *
    *WHEN TIME.MONTHNUM
    *IS 8
    *FOR %YEAR%=%TIME_SET%.YEAR
    *FOR %MONTH%=AUG,SEP,OCT,NOV,DEC
    *REC(FACTOR=1/5,TIME="%YEAR%.%MONTH%",ACCOUNT="TEMPSTUDYEDU")
    *NEXT
    *NEXT
    *ENDWHEN
    *ENDWHEN
    *COMMIT
    Thanks,
    Prasanth.

    I think your formula is correc the %YEAR% is not a valid, Can you trap that and see what is being passed, you may also try to split the year out of %TIME%
    hope it helps.

  • Get month and year

    I need to pick up the month and year and display it like
    Month/Year
    I am a newbie and i am not sure how to accomplish this. Do i perform this function using pl/sql and return the value. If anyone could help me with ideas i would appreciate it.
    thanks

    select to_char(sysdate,'monthyyyy') from dual;

  • Problem in conversion of month and year from R/3 into 0calmonth of BI

    Hi,
    I have to convert two fields of R/3 Calendar month and year into one field of Calendar year/month of BI.
    How can i do this..... i have tried using concatenation formula in transformation rules but its not working and converting 09, 2006 into 06.2009.
    Please help me if you guys have any idea.
    regards

    Why do you want to combine CALMONTH and CALYEAR ??
    CALMONTH will give you both month and year (eg: 09.2007)
    you can directly map (R/3)KMONTH to 0CALMONTH(BI).

  • Using an expression in SSRS to display rolling 12 month and year to date volumes

    I need some help in writing an expression in SSRS. I have a table that contains date columns and rows that contain different types of data groups. (e.g. total number of items received during the month, total dollars for the month, etc.) I want to add two
    new columns to the end of the report that will display a rolling twelve month total for each of the different rows of data. Plus a column that would show year to date totals for the same rows.
    I was thinking I could accomplish this by adding expressions for each row in the new 'rolling twelve month' and 'YTD' columns in my report however, I'm not sure how to structure the expressions to achieve this.
    Here is an example of how my report currently looks. (I added a pipe delimeter in case the formatting changes once this is submitted.)
                             Jan-2014 | Feb-2014 | Mar-2014 | Apr-2014 | Rolling 12 mth | YTD
    Items received     100 | 35 | 45 | 12 | 192 | 192
    Dollars                $50.00 | $25.00 | $120.00 | $15.00 | $210.00 | $210.00
    Any guidance you can provide would be appreciated.
    Thank you  

    This example shows how to get what you need. It'll take modifying your query to add two cased columns onto the end.
    DECLARE @forumTable TABLE (periodYear INT, periodMonth INT, periodMonthName VARCHAR(12), periodDollars MONEY, periodItems INT)
    DECLARE @i INT = 0
    SET NOCOUNT ON
    WHILE @i < 24
    BEGIN
    INSERT INTO @forumTable (periodYear, periodMonth, periodMonthName, periodDollars, periodItems)
    VALUES (YEAR(DATEADD(MONTH,-@i,GETDATE())), Month(DATEADD(MONTH,-@i,GETDATE())), DATENAME(MONTH,DATEADD(MONTH,-@i,GETDATE())), 1000-@i, 100-@i)
    SET @i = @i+1
    END
    SET NOCOUNT OFF
    SELECT *,
    CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodItems ELSE 0 END AS ytdItems,
    CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodDollars ELSE 0 END AS ytdDollars
    FROM @forumTable

  • Month and Year-To-Date Grouping

    Hello,
    I have 4 key figures.  For each of the key figures I need to display the value for the month and the value for the year-to-date.  Example, if the user selects October as the month the query should display only the totals for October and the totals from January to October.  The user does not want to see the totals for January, February, March and so on. 
    ........................Month of October.................Year-To-Date
    No. of Orders .................. 3,005..................... 22,950
    Order Value ..................190,000................ 5,900,000
    Canceled Orders .....................7........................... 60
    Value of Canceled Orders......700........................8000
    Can someone tell me how I go about doing that?

    Hello MIG,
    I guess you can create a structure for your key figures at the rows area of the query and a structure for your dates (e.g. fiscal periods) at the columns area. For your columns, you will need two restricted key figures. The first key fgure will be for your user's current month (e.g. Oct) -- this will be equal to fiscal year/period restricted by a user entry variable for the current month. The second key figure will be for your year to date KF (e.g. Jan to Oct) -- this will be equal to fiscal year/period restricted by a customer exit variable that computes for the date range between Jan and the user's current month. <b>OR</b> you can ask the user to input the initial date (should be defaulted to Jan 2006*) and the current month in a date range -- this will be an interval variable. Hope this helps.
    Juice

  • Cannot get Month and Year display off screen

    In Iphoto 6 I have photos that I imported. I cannot get the middle dark oval in the center of the screen to stop displaying on the photos.
    It makes it very difficult to edit the photos when I cannot see the center of the photo.
    How do I stop the display of the month and date

    In iPhoto Preferences, Appearance, uncheck "Show scrolling information."

  • How to get the currrent month and year from a new date object

    If I create a new Date object as "d",
    java.util.Date d = new java.util.Date();how can I format the date to get the current Month as 'Jan' and the current year as '2008'. So if I have something like d.getMonth() gets the current month as 'Oct' and d.getYear() gets '2008'
    Thanks,
    Zub

    [Read the flamin' manual you must. Hmm.|http://en.wikipedia.org/wiki/RTFM]
    ~~ Yoda.
    Well no actually, he didn't say that, but he should have.
    Cheers. Keith.
    PS: Don't say that to a 7 foot pissedOff wookie when he's got his head stuck in a smoking hyperdrive, and you're being chased by a S-class battle cruiser... Ask Yoda how he got to be so short.
    PPS: It is the SimpleDateFormat you seek ;-)
    Edited by: corlettk on 14/10/2008 22:37 ~~ Also far to slow... but funny.

  • Default Month and Year in Date Paramater

    Hi,
    I have a question and not able to understand how to show a default current month year i.e 112010 as a deualt value in the prompt.
    Thanks in Advance,
    Poojak

    one more problem i found with that code is:
    if current date is January's date, it gives 12010 instead of 012010 and if you are filtering column is holding values like mmyyyy format, it'll give no results..
    i want you to create a repository variable which holds current_date format in mmyyyy format..
    now, use that repository variable here in default section by selecting server variable..
    select to_Char(sysdate, 'mm') || to_Char(sysdate, 'yyyy') from dual

Maybe you are looking for

  • Managers can't see their employees when creating apprisal documents in Performance Management

    Hi All, I'm looking for you experts to enlighten me regarding an issue with the SAP Performance Management solution. We have recently (2013) implemented the Performance Management solution and everything has worked as expected. Now, we are in the pro

  • How can I get my browser to display thumbnails, images, and the background?

    I've had this problem for months now. I've tried uninstalling and reinstalling, resetting, everything I could think of. However, the problem remains. The background is never there, thumbnails are never there, images are invisible. It's basically just

  • Using substring function with error

    Hi Guys, I have a source field with 1200 characters which need to map to multiple target segments for  132 count of this source field. This is not a mandatory field so it sometimes come without any value. I am using substring function to breakout the

  • Delete attachment from master data

    Hello, I need to delete .pdf file from attachment list of one material but there is no delete button. How could I delete it? Thank you

  • Which IDE is suitable for GUI in Java?

    Which IDE is suitable for GUI in Java? I have kind of complex form with many text fields and buttons in a Java application. I have been trying with Netbeans, everything is fine with Netbeans but it is a huge problem when all the graphics components m