Need month in month-year order?

Hello Experts,
The output of below SQL query is as shown in below fig,
CREATE TABLE DBO.TEST_DATA(PU_ID INT NOT NULL, PU_DATE DATE NOT NULL, X_COUNT INT NULL, Y_COUNT INT NULL)
INSERT INTO DBO.TEST_DATA VALUES(28, '2014-01-01', 10, 20), (28, '2015-01-01', 30, 20), (28, '2014-12-12', 10, 20), (28, '2015-02-02', 10, 20)
SELECT @PIVOT_COLS = STUFF((SELECT DISTINCT '],[' + CONVERT(CHAR(3), PU_DATE, 0) + '-' + CAST(YEAR(PU_DATE) AS VARCHAR) FROM TEST_DATA FOR XML PATH('') ), 1, 2, '') + ']'
SET @PIVOT_QUERY = N'SELECT *'+ 'FROM ( SELECT * FROM (
SELECT CONVERT(CHAR(3), PU_DATE, 0) + ''-'' + CAST(YEAR(PU_DATE) AS VARCHAR) PU_DATE, SUM(X_COUNT) X_COUNT, SUM(Y_COUNT) Y_COUNT FROM TEST_DATA
GROUP BY CONVERT(CHAR(3), PU_DATE, 0) + ''-'' + CAST(YEAR(PU_DATE) AS VARCHAR) ) TMP
UNPIVOT
(COL FOR [GROUP] IN (X_COUNT, Y_COUNT) ) AS UNPVT ) PVT ' + 'PIVOT ' + '(MAX(COL) FOR PU_DATE IN (' + @PIVOT_COLS + ')) AS J'
EXEC(@PIVOT_QUERY)
Here Month-Year order in output column is not correct. I need below order,
JAN-2014->Dec-2014->Jan-2015->Feb-2015
Please suggest. Thanks!

Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
A table has to have a key to be table.  Here is my guess at a repair job: 
CREATE TABLE Test_Data
(pu_id INTEGER NOT NULL
  REFERENCES PU(pu_id),
 pu_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
 PRIMARY KEY (pu_id, pu_date),
 x_count INTEGER,
 y_count INTEGER);
Identifiers are not numeric in a good schema. What math do you do with them? They are also the key in the table that models the entity they identify. Where is the PU table (and what is a PU anyway)? 
INSERT INTO Test_Data
VALUES
(28, '2014-01-01', 10, 20), -- crap! No key in this mess!! 
(28, '2015-01-01', 30, 20), -- 
(28, '2014-12-12', 10, 20), 
(28, '2015-02-02', 10, 20);
A PIVOT is not a query and not even part of SQL. It is how Microsoft programmers who do not know RDBMS or have a report writer violate the tiered architecture of SQL. We also do not use XML mixed in SQL. It is a bitch to maintain, has poor performance and again
violates the tiered architecture principle. 
A query is not sorted because it is a table. A file in COBOL can be sorted and that seems to be what you really want to write. 
Old COBOL love the Sybase CONVERT() string function to avoid SQL temporal data. 
We never use SELECT * in production code; Google it. Not only are you generating code, you are generation bad code. 
Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
The report period table gives a name to a range of dates that is common to the entire enterprise. 
CREATE TABLE Month_Periods
(month_name CHAR(10) NOT NULL PRIMARY KEY
   CHECK (month_name LIKE <pattern>),
 month_start_date DATE NOT NULL,
 month_end_date DATE NOT NULL,
  CONSTRAINT date_ordering
    CHECK (month_start_date <= month_end_date),
etc);
These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
You caqn now sort or group things on the "month_name"column's substrings.  
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Month Year values based on Posting Date

    In my super huge extra large InfoCube (0CFM_C10) I got a lot of data. I take Posting Date, some KFG and CalMonth/Year. Unfortinally CalMonth/Year duplicates records, if I drop it off the columns/rows I get valid data by Posting Date.
    My question is this - is it possible to create some MonthYear Calculated KFG/field/formula or smthng. based on Posting Date? In other words I need Month/Year in rows/ columns or free characteristics...
    Edited by: Gediminas Berzanskis on Mar 18, 2008 10:18 AM

    Dear,
    When canceling a payment which was created in previous posting periods,
    we  get system message "Date deviates from permissible range",so
    the workaround is changing back the posting period to the previous one
    and try to cancel the payment.
    However,another system message pops up when we try to cancel payment
    after changing back the posting period,which is the "creation date" or
    "posting date".
    In this scenario, you should select the second option from the
    cancellation options window, which is the 'Creation date'. I would like
    to explain more below.
    Posting Date- means the posting date of the cancellation document, it's
    not the posting date of the incoming payment that you wanna perform the
    cancellation. In your case, selecting this 'posting date' option, system
    deems that you want to post this cancellation document on its own
    posting date.
    Creating Date- means the posting date/creation date of the incoming
    payment, it makes sense that the system works fine if you select this
    option. If you cancel the incoming payment and check the JE generated,
    you will find that the posting date of this cancellation document is
    actually recorded as the posting date of the incoming payment.
    Wish it helps you.If you have any problems,please kindly let me know.
    Thanks and best regards,
    Apple

  • Creating charts that represent current year in Months in order to show YTD performance by month

    I continue to struggle with what, to me, seem to be the simplest things in SSRS.  I have spent over two days trying desperately to get a chart to properly show the quantities of Manufacturing Orders that we have made each month, Year To Date. 
    Below is the closest I’ve been able to come and the axis is still off by one month and not in sync at all with my data. 
    Then when I run the report for other part numbers, that only have MO’s in say two months (Jan & Jun), they don’t even behave scalar and I get the following screwed up mess.  Notice the two columns have decided to fill most of the scale and they
    did not skip the four months between Jan and Jun and they also are completely out of sync with my scalar x-axis!
    My goal is to create a chart that can be run for any part number on any day and show how many times it has been built during the current calender year.  Chart should always show months of current year starting Jan on left and ending with Dec on
    right (even if I am running report in February for example).  Then for each month that we have data, it should show the QTY on the column chart and leave blank columns for months with no data.
    Can anyone help me with this? 
    Chris

    Hi Chirs,
    From your desription, you want to createa a chart to show all the months on the chart no matter it has data on that month or not, rigth? If in this case, we can create an other dataset to show all the month, and then use the lookup function to get the month
    QTY. The steps below are for you reference.
    Create an other dataset use the query below.
    DECLARE @TMP TABLE (Month nvarchar(20),QTY INT)
    INSERT @TMP SELECT 'Jan',0
    INSERT @TMP SELECT 'Feb',0
    INSERT @TMP SELECT 'Mar',0
    INSERT @TMP SELECT 'Apr',0
    INSERT @TMP SELECT 'Mat',0
    INSERT @TMP SELECT 'Jun',0
    INSERT @TMP SELECT 'Jul',0
    INSERT @TMP SELECT 'Aug',0
    INSERT @TMP SELECT 'Sep',0
    INSERT @TMP SELECT 'Oct',0
    INSERT @TMP SELECT 'Nov',0
    INSERT @TMP SELECT 'Dec',0
    SELECT * FROM @TMP
    Drag [Month] filed to Category Groups and drag [QTY] field to Values.
    Then change the of [QTY] to:
    =Lookup(Fields!Month.Value,Fields!Month.Value,Fields!QTY.Value,"DataSet1")
    The report looks liek below.
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • Month/Year reverse countdown help needed

    I need to create a simple reverse countdown that only needs
    the detail level of Months and Years. All of the tutorials I've
    found online are for counting down smaller intervals of time, like
    days, minutes, seconds, and milliseconds.
    I'm not very experienced with the code needed for such a
    timer, but essentially what I would like to have happen is:
    1. The current Month and Year are displayed onscreen.
    2. I click the mouse, and the Month and Year begin to count
    BACKWARDS, as if going back in time, so the Year would go from
    2007, to 2006, to 2005, etc, while the 12 months of the year would
    count down in reverse to coincide with the Year.
    3. When I click the mouse again, the countdown stops at
    whatever month/year it happens to be, I assume all the way back to
    the Year 0 if I let it play to the end.
    BONUS points if this reverse countdown could speed up over
    time, so that it appears to begin slowly, and rapidly speed up as
    the timer goes further back in time.
    Note that I do not need to use the ACTUAL date taken from the
    computer's clock, I'd be happy to just enter in, say "June 2007" as
    the start date and have it reverse from there. So even something
    that would just countdown from the numeral "2007" to "0" while a
    movieclip of the 12 months cycling along could work, though I have
    no concept as to how to control/increase the speed of such an
    animation as it plays.

    put the months in an array "december" to "january", and set a
    variable equal to the start year and an index that corresponds to
    the start month. display the start year/month.
    start a loop (setTimout would work) with a variable call
    frequency that calls a function that
    1. increases your array index (decreasing the year and
    restarting your index at 0 after the last array element is
    displayed) and displays the updated month/year
    2. decreases the variable call frequency and define another
    setTimeout.

  • I need FM calc. days/months/years between 2 dates but computes the work day

    I need FM calc. days/months/years between 2 dates but computes the work day.
    someone knows ?

    Hi,
    The FM is 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    Check the following example:
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Regards,
    Bhaskar

  • Need to display "Calendar Month/Year" at report level from Calendar Day

    Hello Experts,
    I have a scenario in which I have 0CALDAY (e.g. 01.01.2009) along with other fields available in my report. My requirement is to display "Calendar Month/Year" (01.2009) in my report. Is it possible to have "Calendar Month/Year" in my report from 0CALDAY, by making changes to the query, as I cannot remodel the underlying InfoCube.
    Many Thanks,
    VA

    What you mean with huge - 100 Mio dataset?
    The import of the new infocube will be also take a long time - the database must be insert a new field for every dataset.
    => is this a big infocube, then don't use virtual infoobjects.
    => on a big infocube is important to have a good datamodel - please insert always all 11 infoobjects for the time dimension.
    Sven

  • Date for Month year only?

    I Have a report being done where, the user wants to see the 'slow moving inventory' for a 2 month period.
    It's not automatic, the past 2 months. they can select which 2 months they want. So, I was thinking of the best way for the parameters.
    Maybe just have them enter one? month/year. but in any case if i do a from and to, I dont' need the entire calender- is there  a way to display just the month and year? if not i can create the parameter that way.

    I would create a command (SQL Select statement) to use for data for a dynamic prompt.  It might look something like this in Oracle (allows for two full calendar years in the past):
    Select distinct
    To_Char(OrderDate, 'MMM-YYYY')  as MonthYear
    from Orders
    where EXTRACT(Year from OrderDate) >= (EXTRACT(Year from Sysdate) - 2)
    Or like this in SQL Server:
    Select distinct
    Left(DateName(month, OrderDate), 3) + '-' + DateName(year, OrderDate) as MonthYear
    from Orders
    where Year(OrderDate) >= (Year(GetDate()) - 2)
    DO NOT link the command to anything in the report - its sole purpose is to provide data for a dynamic prompt.  Crystal will complain that this is generally not supported, but it will work in this situation.
    Now create a dynamic parameter that will use this data - DO NOT use any other data from your report tables!  This parameter will identify the start month for the report.
    Lastly, you'll need to create a two formulas - one that will calculate the start date from the parameter value and another that will create the end date.  If the parameter is called {?StartMonth}, they might look like this:
    {@StartDate}
    StringVar monthName := UpperCase(Left({?StartMonth}, 3));
    //get the month number
    NumberVar mn := Switch (
      monthName = 'JAN', 1,
      monthName = 'FEB', 2,
      monthName = 'DEC', 12);
    //get the Year number
    NumberVar yr := ToNumber(Right({?StartMonth}, 4));
    //return the first day of the start month:
    Date(yr, mn, 1)
    {@EndDate}
    //Subtract one day from the start of the month 2 months after the start date to get the end of the
    //month after the start date
    DateAdd('m', 2, {@StartDate})  -  1 
    Use these formulas in your selection criteria for your report.
    -Dell

  • Fiscal Month/Year Date Calculations

    Hi Gurus,
    I am trying to create a fiscal year and fiscal month offset using filter advanced SQL in answers. The “Offset” should allow to define a period of time + or – from a given starting point in order to report on a period of time. For example the Current Month Offset - When the variable is defined and set-up in the “Time” drop down menu in Answers. You would select Current Month Offset and in the create/edit filter dialog the Current Month Offset column contains a value of 0 for the most recent loaded month of data, a value of -1 for the month prior to that and so on. By selecting the “Operator”, “is between” and “Value” -5 and “Value” 0 you would filter to display the last 6 months.
    I created the offset with calendar year using the Advanced filter and worked fine for if i need to change the year to what ever value
    (((YEAR(CURDATE())-YEAR(Time.Date)) * 12) + (MONTH(CURDATE())-MONTH(Time.Date))) * -1 = -1
    The issue comes when i create for Fiscal year and Fiscal month using filter advanced SQL it throws an error
    (((FISCAL YEAR(CURDATE())-FISCALYEAR(Time.Date)) * 12) + (FISCAL MONTH(CURDATE())-FISCAL MONTH(Time.Date))) * -1 = -1
    for fiscal year it throws an error below
    Error getting drill information: SELECT Time."Fiscal Year" saw_0, Time."Fiscal Year" saw_1 FROM "AAFES Procurement - Purchase Orders" WHERE Time."Fiscal Year" = (((FISCAL YEAR(CURDATE())-FISCALYEAR(Time.Date)) * 12) + (FISCAL MONTH(CURDATE())-FISCAL MONTH(Time.Date))) * -1 = -1
    Error Details
    Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
    Odbc driver returned an error (SQLExecDirectW).
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <CURDATE>: Syntax error [nQSError: 26012] . (HY000)
    SQL Issued: {call NQSGetLevelDrillability('SELECT Time."Fiscal Year" saw_0, Time."Fiscal Year" saw_1 FROM "AAFES Procurement - Purchase Orders" WHERE Time."Fiscal Year" = (((FISCAL YEAR(CURDATE())-FISCALYEAR(Time.Date)) * 12) + (FISCAL MONTH(CURDATE())-FISCAL MONTH(Time.Date))) * -1 = -1')}
    Thanks
    Simmz

    Hi,
    Kindly refer the below link it may help you.
    http://obieeelegant.blogspot.com/2011/06/obiee-date-expressions-reference.html
    Thanks
    Deva

  • Previous month year

    I have 2 tables-> facts and facts1 and i have to create a "sale revenue - last completed month" metric based on the columns of the tables.
    the formula on the metric right now is CASE WHEN ."Last Completed Month Indicator" = 'Y' THEN ("Sale Order Cost" +"Sale Order Cost Promotional Adjustment") / USD SPot Rate" END
    i have another table "month year" which has a columns "previous month year key no" which is in the format 190001 ( january 1900) ,"previous month year description" , "previous month year name".
    I need to use this previous month year column and put it in the metric above and calculate the revenue for last completed month. Can i do it???
    Thanks!

    Hi,
    what is the granularity of fact table and how is it related to month year table?
    Also are the fact tables partitioned? If they are partitioned AGO and TODATE functions cannot be used.
    Is any of the fact tables aggregated???
    -bifacts
    http://www.obinotes.com
    J

  • Monthly & Yearly Closing

    Hi Sappers!
    1. I would like to know what steps & transaction codes are involved in period end (monthly & yearly) closing in FI.
    2. How do we carry forward the balances to the next period? Will opening & closing periods in OB52 achieve this?
    3. In our existing system once we close a particular module like Sales Order Module, it automatically transfers the amount in the General Ledger. How do we achieve his in SAP.
    4. Are there any special closing activities involved in quarterly closing?
    Appreciate your time!
    Vj

    Hi,
    Below is list of MEC/YEC transactions reqd usually see what applys in Your case.
    Check List for full closing
    1 Execute Report for Inter Company Activity & Journal Entries
    2 Open posting period for next yr (T.Code: OB52)
    3 Run Business Area's Assignment report. (T.Code: F.50)
    4 Review list of recurring journal entries (T.Code: FBD3)
    5 Execute Recurring Entries for A/R, A/P, G/L (T. Code: F.14)
    6 Process Parked A/R, A/P, G/L accounting documents (T.Code: FBV0)
    7 Final Cutoff for the Maintenance of Fixed Asset- Add Transfer and Retire (T.Code: ABUMN)
    8 Run Depreciation in Test Run and post (T.Code: AFAB)
    9 Verify Display Log for Depreciation Test Run (T.Code: AFBP)
    10 Capitalize AUC Assets if needed (T.Code: AIAB, AIBU)
    11 Enter Payroll Data to SAP (T.Code: CAT2)
    12 Verify Depreciation Balances with GL balances ( T.Code: ABST2)
    13 Post Depreciation (T.Code: AFAB)
    14 Execute Asset History Report, and retire assets if needed (T.Code: S_ALR_87011963, ABAVN)
    15 Adjust specific depreciation areas if necessary (T.Code: ABCO)
    16 Reconcile AM sub ledger with GL (T.Code: ABST2)
    17 Check Bank Data (T.Code: S_P99_41000212)
    18 Review AR Open Items (T.Code: FBL5N)
    19 Review AP Open Items (FBL1N)
    20 Execute Pending Invoices(T.Code: MRBP)
    21 Clear Open Item for GRIR, freight (T.Code: F.13)
    22 Reconciliation of Financial Documents and transactional figures (F.03)
    23 Open new CO Posting Period: (T.Code: OKP1)
    24 Compare current (cost estimates) with last current price (Moving Avg) ( T.Code: OKBH)
    25 Update current cost price to material master price field (T.Code: CK11N, CK24)
    26 Process Freight charges, Match SD freight to actual (T.Code: V-31)
    27 Review Internal Order Postings(T.Code: OKSA)
    28 Settle All Orders (T.Code: KO88)
    29 Verify All Post Goods Issue have been Invoiced (Billing Due List) (T.Code: VF04)
    30 Review SD Billing Doc from prior month that have not yet been released to accounting (T.Code :F.2D)
    31 Reconciliation of MM movements in Transit Intra-SAP to Non SAP
    32 Reconcile PI Inventory with SAP (T.Code: MI07)
    33 Perform Manual Adjustment if needed (T.Code: F-02, FB50)
    34 Verify balance of the GR/IR account ( T.Code: MB5S)
    35 Post Accruals and Deferrals (T.Code: FBS1)
    36 Clearing of Cancelled Documents (T.Code: F-03, F-32, F-44)
    37 Check Profitability Segment Adjustment (T.Code: KISR)
    38 Aging Report-Reconcile GL balances with sub ledger balances AP ( T.code: FBL1N, FBL5N, FBL3N)
    39 Check the check run numbers (T.Code: FCH1, FCHI)
    40 Bank reconciliation Data (T.Code: FF67 & FEBA)
    41 Enter Tax Journal Entry (T.Code: FB41)
    42 Reconcile GL balances with sub ledger balances AR/MM/AP ( T.Code: F.03)
    43 Display Balance Sheet Adjustments (T.Code: F.5F)
    44 Post Balance Sheet Adjustments (T.Code: F.5E)
    45 Post Foreign Currency Valuation (foreign exchange) (T.Code: F.05)
    46 Check generic cost centers for posting with wrong accounts
    47 Correct wrong postings on generic cost centers
    48 Check Validation dates for Cost Centers, Cost Elements, CO area (T.Code: GGB0)
    49 Check COGI--for both month end and year end
    50 Doubtful receivables (T.Code : F104)
    51 Verify In-transit Inventory
    52 Reconcile PA to G/L (T.Code: KE5U)
    53 Post Cost Center Assessments and Distributions (T.Code: KSU5 & KSV5)
    54 Run CO-FI Reconciliation to balance (T.Code: KALC)
    55 Run BW reports P&L and Balance Sheet
    56 Maintain CO yr variant (T.Code: KCRQ)
    57 Fiscal Yr Balance carry forward AP/AR/AM (T.Code: F.07,
    58 Fiscal Yr Balance carry forward CO (T.Code: CXS1)
    59 Fiscal Yr balance carry forward FI ( T.Code: F.16)
    60 Fiscal Yr balance carry forward PCA (T.Code: 2KES)
    61 Set Document number ranges - FI - new year (T.Code: OBH2, OBA7)
    62 Set Document number ranges AP/AR - new year (OBA7)
    63 Generate Financial statement Reports ( T.Code:OB58) OR (T.Code: FSE2)
    64 Change Fiscal Year For Assets (T.Code: AJRW)
    65 Year end Closing-- Asset Accounting--final for year end (T.Code: AJAB)
    66 Close CO Posting Period : (T.Code: OKP1)
    67 Close Prior A/R Posting Period ( T.Code: OB52)
    Regards
    Parag

  • How to Include previous Month/Year in Transformation

    Hi,
    From Source System (DB Table;DB Connect)
    Location_ID,EMP_ID,AMOUNT
    There is no date field avaliable in the source system.
    The Data load to BW will me Monthly frequency...I,e:Data will be loaded once in a Months on 1st of every month.
    My requirment is to Include a date field in BW transformations which input previous month/year data for every record
    How can i do that and wether do i need to write a start or field routine in transformations
    Code please
    Thanks

    Hi Pal,
    You could use the following code to achieve this:
    DATA: v_calmonth(6) TYPE c,
          v_month(2) TYPE c,
          v_year(4) TYPE c.
    v_month = sy-datum+4(2).
    v_year = sy-datum+0(4).
    IF v_month = 1.
      v_year = v_year - 1.
    ENDIF.
    IF v_month = 1.
      v_month = 12.
    ELSE.
      v_month = v_month - 1.
    ENDIF.
    CONCATENATE v_year v_month INTO result.
    Hope this helps.
    Thanks and Regards
    Subray Hegde

  • Date Calculations - Adding 1 to the day and adjusting month/year

    Hi all,
    I have a date field in MM/ DD/ YYYY format. If I add 1 to the DD (day) field, and I hit the end
    of the month/year I need to adjust the MM and YYYY accordingly.
    Is there is an existing class/method in the JAVA API that would handle somthing like this??
    If so , I can't find it..... I don't want to re-invent the wheel creating a Date Handling routine just
    for this program.......
    Thanks very much

    This is overkill... (and sorry that this post is over a year later than the original post... hopefully somebody will benefit from it :)
    Calendar.getInstance() by default instanciates a GregorianCalendar
    object. (check the src).
    Therefore:
    Calendar cal = Calendar.getInstance();
    cal.setTime(d); // where d = java.util.Date or java.sql.Timestamp
    cal.add(Calendar.DATE, numberOfDays);
    return cal.getTime();
    public static java.util.Date
    adjustDateBy(java.util.Date d, int numberOfDays) {
    java.util.GregorianCalendar cal = new
    java.util.GregorianCalendar();
         cal.setTime(d);
    cal.add(java.util.GregorianCalendar.DATE,
    numberOfDays);
         return cal.getTime();

  • Month,year wise

    month,year wise query.
    Posted: Jan 3, 2012 11:28 AM Edit Reply
    i have from anf to date parameter
    if i enter from date 13-jan-2011 and to date is null (upto as on date )
    i created matrix format.
    but i need the how to print the months in matrix column cell
    ex: dec/2010 jan/2011 feb/2011 mar/2011 .... dec/2011 jan/2012
    based on from and to date parameters.
    we need to start 31/dec/2010
    how to write the query.

    what is the month & year on which you're based, to collect the data?
    Thanks & Best Regards,
    HuaMin

  • FM to get previous fiscal month/year and calendar month/year for a date.

    Hi All,
    I am having a requirement to extract some data based on either the previous fiscal month/year or the previous calendar month/year. There is no company code input to find the fiscal/calendar month/year.
    At selection screen, user can select either fiscal or calendar selection.
    Based on the selection, the data will be extracted.
    For the system date, we need to calculate previous fiscal month/year or previous calendar month/year and populate the calculated data back to the selection-screen.
    Can you one of you please suggest an FM to find previous fiscal month/year and previous calendar month/year.
    Thanks in Advance,
    Regards
    Gowthami

    Hi Gowthami,
    You can use following function module to calculate previous / next day or month or year.
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    =
            sign      = '-'
            years     =
          importing
            calc_date = .
    Here, you can give '-' to sign, if you want previous day / month / year.
    Here, you can give '+' to sign, if you want next day / month / year.
    And depending upon your requirement, you can pass suitable value to days / month / year.
    e.g. To calcualte last month,
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    = 1
            sign      = '-'
            years     =
          importing
            calc_date = wv_prev_month.
    so it will give '23-01-2008' . Then convert it in the required format as per your requirement using string function concatenate.
    Hope this help you.
    Regards,
    Anil

  • How to derive date from given month, year and day?

    Hi all,
    I have a doubt in date function. I need to create a date from the given month, year and day. How can i do it?

    consider this example
    REPORT zconvertdate001 .
    TYPES : BEGIN OF tt_date_in,
            day(2),
            sep1,
            month(3),
            sep2,
            year(4),
            END OF tt_date_in.
    DATA : wa_date_in TYPE tt_date_in VALUE '07-Jul-2006'.
    TYPES : BEGIN OF tt_date_out,
            day(2),
            month(2),
            year(4),
            END OF tt_date_out.
    DATA : wa_date_out TYPE tt_date_out.
    TRANSLATE wa_date_in-month TO UPPER CASE.
    SELECT SINGLE mnr
    INTO wa_date_out-month
    FROM t247
    WHERE spras EQ sy-langu
    AND   ktx EQ wa_date_in-month.
    CONCATENATE wa_date_in-year wa_date_out-month wa_date_in-day
           INTO wa_date_out.
    WRITE : / ' Date in:', wa_date_in,
            / 'Date out:', wa_date_out.

Maybe you are looking for

  • Oracle EBS R12 DR - Status Column Shows N in FND_NODES

    Hi, We implemented DR for Oracle EBS R12 (2-Node Oracle 10gRAC, 2-Node Apps) using Oracle Data Guard. During the Failover testing we noticed that the Status shows N for the DB Nodes and First Apps Node. It shows Y only for the 2nd Apps Node in the FN

  • Linked Lists

    I am trying to create a linked list with an object called ClassID But I am confused on the constructor. Could someone point me in teh right direction. this is what i got: import java.io.* public class Link      public ClassID id;      public Link nex

  • Is it Possible to Remove a Library from iTunes 12?

    I am trying to fix a synching issue in which, long story short, iTunes 12, without my knowledge, forced a move of my Books library from My Documents folder to the iTunes Media folder, and now the synching of my books is all f***ed up.  So I would lik

  • How to hide fields on Repetitive Area Footer on the last page?

    Hello, How can I avoid printing some fields on the last page, when this fields are on the Repetitive Area Footer, and the Repetitive Area Footer is defined to print on all the pages? I was hoping to do this with fileds linked to (ContinueNextPage) fi

  • ISE: test-radius user check fails

    The ISE user guides suggest to use a username called 'test-radius' as option to the 'radius-server host' commands. This will cause the respective NAD (a Cat3560 in my case) to make an authentication check on each configured ISE every 60 minutes. The