How to Calculate column (Month, Year) from date or timestamp

Hi,
Name
SQL Data Type
Dimension
Column Store Data Type
Key
Not Null
Default
Comment
T_STAMP
TIMESTAMP
LONGDATE
How to generate Month and Year from timestamp field in Analytic View.
Please provide me some valuable input. I have searched SCN before posting this discussion.

Hi KD,
You can apply the following formulas in the expression:
For Year :
leftstr(string("Timestamp"),4)
For Month:
midstr(string("Timestamp"),6,2)
Regards,
Krishna Tangudu

Similar Messages

  • How to derive month/year from date in SAP BW 3.5 data flow

    Hi
    How we can derive cal year/month and fiscal month/year from date in SAP BW 3.5 data flow (we're using transfer and update rule)..
    Thanks,
    PK

    Hi,
    if you have any date filed in source side you can just map to any time char system will automatically convert to target objects.
    please look at the screen shot for understanding. (not 3.x it is 7.x)
    Thanks,
    Phani.

  • Extract Month & Year  From Date

    Hi All,
    I have a key figure quantity and i want the data on date,for the month and for the year.
    i create the variables for the date,for the month(ie from date to date) and for the year(ie, from date to date) seperatly that means i have three input variables which may sometimes create confusion.
    My problem is that I want to enter only date and the variable itself calculate the month and year from the date so that it returns the data as desired above.
    for eg. : Now i to enter date : 3/14/2009
              enter MTD (FROM/TO) : 3/01/2009 - 3/14/2009
              enter YTD (FROM/TO) : 4/01/2008 - 3/14/2009
    I want to enter only date : 3/14/2009
    and the variable itself extract the month and year till date.
    and also the same variable calculates number of days so that need not to take the formula variable of date difference to calculate the average qty.
    Neha..

    Hi,
    1. Create User Entry Variable on 0CALDAY : Name = ZCDAY.
    2. Craete a Customer Exit Variable on 0CALDAY: Name  = ZMTD.
    3. Craete a Customer Exit Variable on 0CALDAY: Name  = YMTD.
    Properties of Customer Exit Variables.
    Variable reporesents = Single
    Variable Entry = Mandatory
    Processing By = Customer Exit.
    Character = Calender Day
    Here I'm thinking that ZKF is your key figure.
    In columns you create two selections one is for MTD and other is for YTD.
    In MTD selection, drag and drop ZKF and Drag and Drop 0CALDAY and then Right Clcik and Restrict-->
    Selection = Value Range. (In Between) and restrict with the follwoing Variables
    []ZMTD; ZCDAY.
    In YTD selection, drag and drop ZKF and Drag and Drop 0CALDAY and then Right Clcik and Restrict-->
    Selection = Value Range. (In Between) and restrict with the follwoing Variables
    []YTD; ZCDAY.
    Then write the following code in I_STEP = 2.
    DATA: ZT_DT1 TYPE SY-DATUM,
              ZT_DT2 TYPE SY-DATUM,
              ZT_SDT TYPE SY-DATUM,
              ZT_YR(4) TYPE N,
              ZT_DY(2) TYPE N,
              ZT_MT(2) TYPE N,
              ZE_TT(2) TYPE N,
              ZPOPER TYPE POPER,
             ZRELJR TYPE RELJR.
    WHEN 'ZMTD_A'.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCDAY'.
        IF sy-subrc = 0.
          CLEAR: l_s_range.
          ZT_DY = '01'.
          ZT_SDT = loc_var_range-low.
          ZT_MT = ZT_SDT+4(2).
          ZT_YR = ZT_SDT+0(4).
          CONCATENATE ZT_YR ZT_MT ZT_DY INTO ZT_DT1.
          l_s_range-low = ZT_DT1.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
      ENDLOOP.
    WHEN 'ZYTD'.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCDAY'.
        IF sy-subrc = 0.
          CLEAR: l_s_range.
          ZT_DY = '01'.
          ZT_SDT = loc_var_range-low.
          CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
            EXPORTING
              I_DATE               = ZT_SDT
    *         I_MONMIT             = 00
              I_PERIV              = 'V3'
           IMPORTING
             E_BUPER              = zbuper
             E_GJAHR              = zbdatj
           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.
          CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
            EXPORTING
              I_GJAHR              = zbdatj
              I_PERIV              = 'V3'
           IMPORTING
             E_FIRST_DAY          = ZT_DT2
    *         E_LAST_DAY           =
           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.
          l_s_range-low = ZT_DT2.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
      ENDLOOP.
    Thanks
    Reddy

  • Group by month/year from DATE FORMAT column

    Hi Chaps,
    I have a recordset that pulls data from a database, then presents the data in a table. The data is grouped by 'projid', repeated for every 'projid', with a show/hide control, to show all the 'jobid's' relating to that particular 'projid'
    This is what I have so far:
    Code:
    SELECT             
    tbl_projects.projid,
    tbl_projects.projtitle,
    tbl_projects.projdue, DATE_FORMAT(tbl_projects.projdue, '%%d/%%m/%%Y') as projdue_format,
    tbl_projects.projtype, 
    tbl_projects.projinvtype,
    tbl_projects.FK_custid,
    tbl_projects.projcompletedate
    tbl_languaget.langtname,
    tbl_doctype.doctypename,
    tbl_jobs.jobid,
    tbl_jobs.FK_projid,              
    tbl_jobs.jobname,              
    tbl_jobs.FK_langid,              
    tbl_jobs.jobpages,              
    tbl_jobs.jobshipped,
    tbl_jobs.jobinvsent,   
    tbl_jobs.jobtranslatorcharge,    
    'tbl_jobs' as fromtable,
    tbl_customers.custid,
    FROM tbl_projects  
    INNER JOIN tbl_jobs              
    ON tbl_projects.projid=tbl_jobs.FK_projid  
    INNER JOIN tbl_languaget              
    ON tbl_languaget.langtid=tbl_jobs.FK_langid  
    INNER JOIN tbl_customers              
    ON tbl_customers.custid=tbl_projects.FK_custid
    INNER JOIN tbl_costs
    ON tbl_costs.FK_custid=tbl_customers.custid 
    INNER JOIN tbl_doctype
    ON tbl_doctype.doctypeid=tbl_jobs.FK_doctypeid
    WHERE tbl_projects.projstatus='Complete'        
    AND tbl_projects.projinvtype='Costing Sheet'
    AND langtname!='TH'
    AND langtname!='ID'
    AND langtname!='KO'
    AND langtname!='JP'
    AND jobinvsent='y'
    AND FK_custid = %s
    ORDER BY projid ASC", GetSQLValueString($colname_rsInvPending, "int");
    $rsInvPending = mysql_query($query_rsInvPending, $conndb2) or die(mysql_error());
    //$row_rsInvPending = mysql_fetch_assoc($rsInvPending);
    $totalRows_rsInvPending = mysql_num_rows($rsInvPending);
    Code:
    // REPEAT - FOR EVERY PROJECT
      <?php
      $previousProject = '';
      if ($totalRows_rsInvPending > 0) {
      // Show if recordset not empty
        while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousProject != $row_rsInvPending['projid']) {
          // for every Project, show the Project ID
      ?>
    Code:
    // SHOW/HIDE CONTROL
        <tr>
        <td colspan="9" class="highlight"><span class="blueBold"><a href="#" onclick="toggle2('proj1<?php echo $row_rsInvPending['projid'] ?>', this)"><img src="../../Images/plus.gif" border="0" /></a> <?php echo $row_rsInvPending['projid'] ?> - </a></span><span class="blueNOTBold"><em><?php echo $row_rsInvPending['projtitle'] ?></em></span></td>
        </tr>
    Code:
    // SHOW/HIDE
        <?php $previousProject = $row_rsInvPending['projid']; } ?>
        <tr class="proj1<?php echo $row_rsInvPending['projid'] ?>" style="display:none">
        <td>column 1</td>
        <td>column 2</td>
    What I want, is to put in another grouped by stage, where the 'projid's' themselves are in a show/hide region, grouped by 'projcompletedate' (year/month). 'projcompletedate' is in DATE format, but how to I get PHP/SQL to take the month and year and then group them correctly?

    Hi David, I'm not sure if I've got this right, would you mind looking at my latest code?:
    <table border="0" cellpadding="0" cellspacing="0" id="tblinvoice">
        <tr>
          <th>Job Title</th>
          <th>Type</th>
          <th>Language</th>
          <th>Translator</th>
          <th>Total</th>
          <th>Full</th>
          <th>Fuzzy</th>
          <th>Proof</th>
          <th>Full Price</th>
          <th>Discount Price</th>
          <th>Document Format</th>
          <th>Pages</th>
          <th>Typesetting Cost</th>
          <th>EN Proofreading Cost</th>
          <th>Total</th>
          <th>Translator Charge</th>
          <th>Profit</th>
          <th>Profit Percentage</th>
        </tr>
        <?php
          $previousMonth = '';
          if ($totalRows_rsInvPending > 0) {
          // Show if recordset not empty
          do ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousMonth != $row_rsInvPending['themonth']) {
          // for every Month, show the Month Name
       ?>
        <tr>
          <td colspan="18" class="highlight"><?php echo $row_rsInvPending['theyear'] ?> - <?php echo $row_rsInvPending['themonth'] ?></td>
        </tr>
        <?php $previousMonth = $row_rsInvPending['themonth']; } ?>
        <?php
          $previousProject = '';
          if ($totalRows_rsInvPending > 0) {
          // Show if recordset not empty
          while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)) {
          if ($previousProject != $row_rsInvPending['projid']) {
          // for every Project, show the Project ID
       ?>
       <tr>
        <td colspan="18" class="highlight"><span class="blueBold"><a href="#" onclick="toggle2('proj1<?php echo $row_rsInvPending['projid'] ?>', this)"><img src="../../Images/plus.gif" border="0" /></a> <?php echo $row_rsInvPending['projid'] ?> - </a></span><span class="blueNOTBold"><em><?php echo $row_rsInvPending['projtitle'] ?></em></span></td>
        </tr>
        <?php $previousProject = $row_rsInvPending['projid']; } ?>
        <tr class="proj1<?php echo $row_rsInvPending['projid'] ?>" style="display:none">
            <td><?php echo $row_rsInvPending['jobname']; ?></td>
            <td><?php echo $row_rsInvPending['projtype']; ?></td>
            <td><?php echo $row_rsInvPending['langtname']; ?></td>
            <td><?php echo $row_rsInvPending['translator']; ?></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
          <?php } while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)); ?>
          <?php } // Show if recordset not empty ?>

  • Select year from date

    help me..urgent..
    how set query to select year from date by using expression where.
    ex: select sum(salary)
    from table
    where year(date)=2007
    group by name;
    just something like that..help me.plezz..

    select *
      from (
             select 1 as rn, to_date('09052007','ddmmyyyy') as dt from dual union all
             select 1 as rn, to_date('09052006','ddmmyyyy') as dt from dual
    where to_char(dt,'yyyy') = '2007'; or
    select *
      from (
             select 1 as rn, to_date('09052007','ddmmyyyy') as dt from dual union all
             select 1 as rn, to_date('09052006','ddmmyyyy') as dt from dual
    where extract(year from dt) = 2007;

  • How to calculate the previous year YTD balance in profit & loss statement

    Dear all,
    I would like to seek for advice on how to calculate the previous year YTD (Year to date) balance in profit & loss statement
    For example, if I enter May 2009, the YTD value should be a sum up of value from Jan to May.
    I have tried the current year YTD could be set in column selection dimension "financial period"
    FACT PER( Code = YearFirst(@Per):@Per )  Order By PER.Code Descending
    Then, I tried the previous year YTD in another column using
    FACT PER( Code = YearFirst(@Per-12):@Per-12 )  Order By PER.Code Descending
    But it failed -> Abnormally display three column, while the financial period I enter 200903 in parameter @Per
    Would anyone kindly help me on that?
    Regards,
    Simon Chiu

    Dear Jim,
    Thanks for your reply.
    However, the problems still cannot be solved.
    My expected output is 1 column listing the YTD value from previous year.
    I have tried two times using both the Code = YTD(@Per-12) and Code = YearFirst(@Per)-12:@Per respectively. However, the Excel display various column.
    I am using Financial Period 200903. In the last three column, it display the data in Financial Period 200901, 200902 and 200903 respectively.
    For the current year, the YTD is correct and show 1 column listing the sum of account in the Financial Period 200901, 200902 and 200903
    Would you kindly advice the code setting and how to set? Also, how I can access the syntax builder?
    Regards,
    Simon Chiu

  • Rip of year from date field

    I have a question. I want to rip of the year from date field. For e.g if date is 01/02/2006 I want just the 01/02 which month and date. I tried to use substr function but it;s giving weird result. I used substr(date, 0,5) but not working. Please suggest.

    If it is a DATE column/variable it is conventional to use TO_CHAR with an appropriate date format, in your case TO_CHAR (date_column, 'MM/YY').

  • Extract year from date

    Hello,
    Iam using obiee 11g, would like to extract the year from date
    CAST(YEAR("ABC"."DATEADDED" ) as varchar(4))
    so used like this
    But i want like if the year is 2011 then only 11 i wants is there a direct function which does that.
    Thanks

    You can use the right function right(year, 2). Will return 11 if year is 2011

  • Conversion from DATE to TIMESTAMP datatype

    Hello,
    My issue is as follows:
    1. I have one variable of type DATE, which I assign the value of SYSDATE
    mydatevar DATE:= SYSDATE;2. I want to find *"today"*, truncated to DAY
      TRUNC (mydatevar, 'DD')
    TRUNC function returns DATE datatype. So I will receive in point 2 for example *'2010-01-13 00:00:00'*.
    3. I want to assign the value from point 2 to a variable of type TIMESTAMP
      mytimestampvar TIMESTAMP := mydatevar;which implicitly will convert the DATE variable to TIMESTAMP.
    Problem: During the conversion (both implicit and explicit conversion with a format mask) I lose the "00" hours and "00" minutes and receive something like this: "10-JAN-13 *12*.00.00.000000000 AM".
    Question: How can I convert from DATE to TIMESTAMP keeping hours and minutes zeros?
    Why I need this conversion: I have a table with a column "column1" TIMESTAMP(0) and I would like to take only those rows from the table, where "column1" is in range from today 12 o'clock in the morning till now (whatever hour it is).
    NLS characteristics of the database:
    PARAMETER                           VALUE
    NLS_LANGUAGE                           AMERICAN
    NLS_TERRITORY                   AMERICA
    NLS_CURRENCY     $
    NLS_ISO_CURRENCY                    AMERICA
    NLS_NUMERIC_CHARACTERS     .,
    NLS_CHARACTERSET                    AL32UTF8
    NLS_CALENDAR                            GREGORIAN
    NLS_DATE_FORMAT                    DD-MON-RR
    NLS_DATE_LANGUAGE            AMERICAN
    NLS_SORT     BINARY
    NLS_TIME_FORMAT                     HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT             DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT     DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                             BINARY
    NLS_LENGTH_SEMANTICS               BYTE
    NLS_NCHAR_CONV_EXCP             FALSE
    NLS_NCHAR_CHARACTERSET     AL16UTF16
    NLS_RDBMS_VERSION             10.2.0.4.0Session parameters are the same.
    DBTIMEZONE is "+02:00".

    Verdi wrote:
    Problem: During the conversion (both implicit and explicit conversion with a format mask) I lose the "00" hours and "00" minutes and receive something like this: "10-JAN-13 *12*.00.00.000000000 AM".I don't think you are necessarily losing any information whatsoever. It's probably more of a function of your NLS_TIMESTAMP_FORMAT and NLS_DATE_FORMAT. For example your NLS_DATE_FORMAT could be setup by default for a HH24 (24 hour time) which would report midnight as "00" hours. However, it looks like your NLS_TIMESTAMP_FORMAT is setup with a "HH" format with a meridian indicator which means 12 hours time.
    Your comparisons should be using date/timestamp data types anyways so as long as the input value is converted properly into a date type this shouldn't matter anyways.
    You can see what is actually stored by using the DUMP function:
    SQL> SELECT  DUMP(TO_TIMESTAMP(TO_CHAR(TRUNC(SYSDATE,'DD'),'MM/DD/YYYY HH:MI:SS AM'))) AS TSTAMP
      2  ,       DUMP(TRUNC(SYSDATE,'DD')) AS DT
      3  FROM DUAL
      4  /
    TSTAMP                                                                      DT
    Typ=187 Len=20: 218,7,1,13,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0                  Typ=13 Len=8: 218,7,1,13,0,0,0,0As you can see the TSTAMP and DT store nearly the same values (218,7,1,13), but the TSTAMP has more precision because of fractional seconds.
    HTH!
    Edited by: Centinul on Jan 13, 2010 7:23 AM

  • Year , Month & Day from Date.

    Hi HANA experts,
      Do help me to resolve this issue
    How can we extract or fetch year from the date.i went through some of the SCN blogs.where they create calculation views...but the steps are not that clear to me.
    can anyone please explain??
    My scenario is :
    I have date field in ANALYTIC VIEW which i have fetched from ECC  tables.
    now i need to get  the year  wise month wise and day wise reports. so what steps i should do in calculation view to get that??
    thanks
    Neeraja

    there is no ECC under SAP...as we are using suite on HANA fro AWS.and there is no restriction done by the basis till now...
    as we are new to these unable to trouble shoot things easily.
    thanks for your reply..

  • Spread Data Over Multiple Months & Years with Data from Multiple Years

    Hello Everyone,
    I have a complex calculation for spreading values over several months spanning mulitle years. Because we have a 36 month rolling Forecast, a more sophisticated calc is required as opposed to hard coding months or years.
    Heres the description:
    Users enter the following data,
    FY11     BegBalance     Number of BOD Members     10
              BOD Options Vesting Months     20
              BOD Options Accounting Value     10
              BOD Options- Number of Shares     100
              BOD Grant Month     Aug
    FY12     BegBalance     Number of BOD Members     5
              BOD Options Vesting Months     10
              BOD Options Accounting Value     5
              BOD Options- Number of Shares     200
              BOD Grant Month     Oct
    FY13     BegBalance     Number of BOD Members     20
              BOD Options Vesting Months     8
              BOD Options Accounting Value     20
              BOD Options- Number of Shares     100
              BOD Grant Month     Feb
    Based on the above;
    "BOD Stock" is calculated as following/month=Number of BOD Members*BOD Options Accounting Value*BOD Options- Number of Shares/ BOD Options Vesting Months
    Start month for the above is based on "BOD Grant Month". So, for instance considering data for FY11:
    The total "BOD Stock" value is $10000 (originating from FY11) with start month of AUG in FY11 and the number of months to spread over is 20 months. So, essentially the "BOD Stock" per month (originating from FY11) is $500 starting from AUG FY11 to Mar FY13.
    Similarly, the total "BOD Stock" value is $5000 (originating from FY12) with start month of OCT in FY12 and the number of months to spread over is 10 months. So, essentially the "BOD Stock" per month (originating from FY12) is $500 starting from OCT FY12 to JUL FY13.
    The challange I am facing is because of the number of months to spread. Because I have data to spread from multiple years and each year's data spills into the following years, each year should accumulate data from prior years. For instance;
    FY11 should include only FY11
    FY12 should include FY11 and FY12
    FY13 should include FY11, FY12 and FY13.
    Could anyone suggest a smarter way to do this without writting code for each year, maybe using @MDALLOCATE function? The following shows how data should be spread and accumulated.
                             BegBalance     Jan     Feb     Mar     Apr     May     Jun     Jul     Aug     Sep     Oct     Nov     Dec     Period
    FY11     Number of BOD Members          10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     100     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Aug     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               10000     #mi     #mi     #mi     #mi     #mi     #mi     #mi     500     500     500     500     500     #mi
    FY12     Number of BOD Members          5     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          10     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     5     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     200     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Oct     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               5000     500     500     500     500     500     500     500     500     500     1000     1000     1000     #mi
    FY13     Number of BOD Members          20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Vesting Months          8     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options Accounting Value     20     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Options- Number of Shares     100     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
         BOD Grant Month               Feb     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi     #mi
              BOD Stock               40000     1000     6000     6000     5500     5500     5500     5500     5000     5000     #mi     #mi     #mi     #mi
    Appreciate your inputs!
    Edited by: user10678366 on Oct 12, 2010 3:21 PM

    Why not use substitution variables for Years? you could have something like &Year1, &Year2, &Year3
    Cheers

  • 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

  • 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

  • Extract Year/Month/ Week From Date

    BW Experts,
      I have a Time Char in a New OSD i am developing. Say the Time char is 0Req_date. This 0req_date is updated using some calculation in my update rules (Say 0Req_Date = Act_dl_dt - Conf_date). Now I have to extract month/ year/ week and populate Time Chars 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK respectively from 0REQ_DATE. Can I do this via respective rules to 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK in the update rules. My concern is as OREQ_DATE itself is a calculated field, can month/year/week be extracted correctly? Hope I have put the question across understandably. Help is appreciated.
    Thanks
    Ashwin

    Hi Ashwin,
    It can be done...you can either put the code for all these derivations in the Start Routine of the update rule, making sure that the 0REQ_Date is calculated before the others. Or you can also calculate just the 0REQ_DATE in the start routine and use the individual update routines to populate the other time chars.
    Processing using the Start Routine is recommended for efficiency and better performance.
    Hope this helps...

  • Week and month calculation from date column

    I have 3 column data like
    with tab as
      select 'Topshop' brand, '10-JUL-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '10-JUL-11' deliverydate, '400' qty from dual union all
      select 'NewSita' brand, '11-JUL-11' deliverydate, '200' qty from dual union all
      select 'LaGress' brand, '12-JUL-11' deliverydate, '300' qty from dual union all
      select 'LaGress' brand, '10-AUG-11' deliverydate, '100' qty from dual union all
      select 'LaGress' brand, '11-AUG-11' deliverydate, '200' qty from dual union all
      select 'Topshop' brand, '12-AUG-11' deliverydate, '300' qty from dual union all
      select 'NewSita' brand, '10-SEP-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '11-SEP-11' deliverydate, '200' qty from dual union all
      select 'NewSita' brand, '12-SEP-11' deliverydate, '300' qty from dual
    ) select * from tabI need to convert it into 4 columns
    Brand | Month | Week(start date) | Qty (sum)
    Please let me know what are the options that i have, especially the date-time calculation functions available to solve such problems.
    Thanks
    w\

    with tab as
      select 'Topshop' brand, to_date('10-JUL-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'Topshop' brand, to_date('10-JUL-11', 'dd-mon-yy') deliverydate, '400' qty from dual union all
      select 'NewSita' brand, to_date('11-JUL-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'LaGress' brand, to_date('12-JUL-11', 'dd-mon-yy') deliverydate, '300' qty from dual union all
      select 'LaGress' brand, to_date('10-AUG-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'LaGress' brand, to_date('11-AUG-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'Topshop' brand, to_date('12-AUG-11', 'dd-mon-yy') deliverydate, '300' qty from dual union all
      select 'NewSita' brand, to_date('10-SEP-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'Topshop' brand, to_date('11-SEP-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'NewSita' brand, to_date('12-SEP-11', 'dd-mon-yy') deliverydate, '300' qty from dual
    ), week_data as (
       select brand
       ,      to_char(deliverydate, 'Month', 'nls_date_language=american') MON
       ,      trunc(deliverydate, 'day') WEEK_START
       ,      sum(TO_NUMBER(qty)) SUM_QTY
       from   tab
       group by brand
       ,      to_char(deliverydate, 'Month', 'nls_date_language=american')
       ,      trunc(deliverydate, 'day')
    ), weeks as (
       select
       w.week_min + (level - 1) * 7 week_start
       from (
          select min(week_start) week_min, max(week_start) week_max
          from week_data
       ) w, dual
       connect by level <= 1 + (w.week_max - w.week_min) / 7
    select
    week_data.brand,
    weeks.week_start,
    nvl(week_data.sum_qty,0) sum_qty
    from week_data
    partition by (brand)
    right outer join weeks
    on (weeks.week_start = week_data.week_start)
    order by
    weeks.week_start,
    week_data.brand;You construct a set of records of all "week_start" dates from your minimum to your maximum (classic connect by level trick.)
    You use a partitioned outer join to fill in the gaps in your sparse data (see doc example [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_10002.htm#i2177515]here.
    Hope that helps you :-)
    (PS. I dislike implicit conversions - that is the only reason I have added a TO_NUMBER to your code within the sum() ;-) )
    (PPS. Actually you probably should have asked this in a new question - I believe it is not really good forum etiquette to continue in a thread that has already been answered...)

Maybe you are looking for