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

Similar Messages

  • 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

  • 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

  • Get day month and year of a date

    Hi all i need to get the week day of a date, the week, the month, the year of a generic date.

    Actually SimpleDateFormat is probably better. Calendar's months are opaque constants.
    http://www.javaalmanac.com/egs/java.text/FormatDate.html

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

  • I want to accumulate rain for the day, month and year; What formula can I use?

    I want to accumulate rain for the day, month and year; What formula or expression can I use.
    I am using a Rain Wise product that converts pulses to an analog value.  The Rain Wise device can be
    set to measure up to 1", 5", or 10".  I will be setting the unit to 10 inches in increments of 0.01 inches.
    What I would like to do is everytime the signal increments I would like to count it as 0.01 then after reaching
    a period of time whether it be a day or a month reset back to zero.
    Need some advise on this problem.
    Solved!
    Go to Solution.

    Hello Ryan,
    Lookout gets a Modbus over Ethernet signal which originates as a 4-20mA input to a Moxa Ethernet I/O Module (E1240) in the field.  In Lookout I created a ModbusEthernet Driver and a tag which scales 0 - 65534 RAW to 0-10 Eng.  [0 - 10 is inches of rain]  Also, another piece of information is that after the rain gauge maxes out at 10 inches it will zero out and start over.
    I though the accumulator was time based and took a sample over a specific time period, for instance, one sample every 30 seconds then accumulate.  If this is so then if I have 5 inches of rain and then it stopped raining, then 30 seconds latter it would sample, it would see 5 inches and add that to be 10 inches when actually it had only rained 5 inches. 
    I really need some help with this process,
    David Lopez
    City of Corpus Christi

  • How to get Week,Month and Year details from a date column

    Hi frenz,
    I've a column like tran_date which is a date column..... I need the next week details based on this column and so on...
    I need month and year details as well based on this tran_date column.... can any one tell me how...
    Thanks in advance

    My example for objects:
    create or replace type date_object as object
      centure number,
      year    number,
      month   number,
      day     number,
      hour    number,
      minute  number,
      second  number,
      daypart number,
      week    number,
      constructor function date_object(p_dt date)
        return SELF as result
    create or replace type body date_object is
      constructor function date_object(p_dt date)
        return SELF as result
      as
      begin
        SELF.centure:= trunc(to_char(p_dt,'YYYY')/100);
        SELF.year:=    to_char(p_dt,'YYYY');
        SELF.month:=   to_char(p_dt,'MM');
        SELF.day:=     to_char(p_dt,'DD');
        SELF.hour:=    to_char(p_dt,'HH24');
        SELF.minute:=  to_char(p_dt,'MI');
        SELF.second:=  to_char(p_dt,'SS');
        SELF.daypart:= p_dt-trunc(p_dt,'DD');
        SELF.week:=    to_char(p_dt,'IW');
        return;
      end;
    end;
    select date_object(sysdate),
           date_object(sysdate).year
    from dual;Regards,
    Sayan M.

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

  • Can we modify the pnp selection screen and get only month and year?

    Dear Freinds,
                  I have requirement where i have to modify the PNP selection screen. So with the help of report category and coding in AT SELECTION-SCREEN OUTPUT  , i have modified all the fields relating to dates . i.e i have removed all the radio buttons (i.e Today, Current month,current year etc) and finally
    i have landed with only Period ( PNPBEGDA & PNPENDDA range) . But i dont want the PNPBEGDA & PNPENDDA range , but i want only is the month and year ( i.e just like the PNPPABRP & PNPPABRJ)
    on my selection screen along with the pernr .
    i have used the below code to close all the fields except pnpbegda and pnpendda.
    AT Selection-Screen output.
    loop at screen.
      IF screen-group4 = '098' .
          screen-input = '0'.
          screen-invisible = '1'.
        ENDIF.
        IF screen-group4 = '092' .
          screen-input = '0'.
          screen-invisible = '1'.
        ENDIF.
        IF screen-group4 = '094' .
          screen-input = '0'.
          screen-invisible = '1'.
        ENDIF.
        IF screen-group4 = '100' .
          screen-input = '0'.
          screen-invisible = '1'.
        ENDIF.
        IF screen-group4 = '104' .
          screen-input = '0'.
          screen-invisible = '1'.
        ENDIF.
        MODIFY SCREEN.
    endloop.
    i.e on my selection screen i want only  month & year combination and pernr -
    when iam using the logical database PNP . Could any one please let me know how can i get only mon & year only on my selection screen .
    If it is possible please let me know .
    Thanks & regards
    divya.

    Hi ,
       The requirement is that the user doesnt want to enter the date range i.e for ex:  01012008 to 31012008.
    As per the requirement the user will enter only the month and year only . so i on the selection screen
    i want only the month and year only . Is there any means i can modify the date period which is there by
    default (PNPbegda and PNPendda) on PNP selection screen. Instead of we givign to the user the
    PNPBEGDA and PNPPENDA i want is only month and year .
    AS already the code has already been written and now they have asked that they want only the month and year on the selection screen.
    Please suggest me in this regard.If iam hiding all the buttons relating the dates fields, and now if iam adding the parameters for the month and year  it is coming below below the fields pernr , personnel ara and subara , company code , payroll area, employee group of the standard fields of PNP selection screen , there by any body could please suggest me how to change.
    regards
    divya.

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

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

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

  • New library did not give me folders divided by day, month and year.  My previous one did.  How do I make this happen?

    Hi All
    Just changed external hard drives and am setting up a new library to pull all the new locations together.  How do I get the library to be subdivided by day, month, year?  It came up just ordered by date but not subdivided.  Seemed simpe but I have been at it for hours with no success.
    Thanks,
    Henry from Vermont

    Rob
    Thanks so much for the quick response.
    History:
    started in LR4 in PC
    Moved to Mac and OSX with LR5 (Mac Pro Book retina with solid state drive
    so fast)
    I had my PC original photos on an external PC drive that was filling up and
    only could be red by mac but not written.
    Just bought a 1tb drive and formated it for Mac
    Moved through finder all photos and LR catalogs from PC 640gig drive to new
    mac formated 1tb and then imported them which did not take a long time and
    did not bring originals into the mac.  This was a new catalogue.  I still
    have the old one and the files on the PC external drive.
    LR finds and displays these originals (a mix of raw and jpegs with a few
    tifs.  A 14 year collection, perhaps 18,000 images) but the list is not
    subdivided in any way, just one large group of photos in date taken
    sequence.  The old catalogue was subdivided by day, month, year.  I may
    have created duplicates but have not checked.  I had a backup copy of some
    lost photos which imported.
    My goal is to have all photos broken out by date.  I must retain edited
    results and would like to maintain meta data.
    Is this enough info?  What else would you like?
    Thanks,
    Henry

  • 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

Maybe you are looking for

  • How can I transfer photos from a memory card to my compter with the hp 8600 ?

    I can't transfer photos from my memory card to the computer. It only gives me the option to print them.

  • DVD Formats

    I'm in the process of having a friend take an old VHS tape of mine and make a DVD from it. I want to be able to play this DVD on my mac mini (combo drive). Would also like to play on my commercial dvd player. He is asking me about which format of DVD

  • Problem While configuring Integrated Scenario

    Hi, While using Integrated Configuration in PI71, where our scenario establishes communication with a File(nfs) to File(nfs) adapter. While testing in Integration Directory via Test Configuration, the scenario produces following error: Problem occurr

  • Using dynamic queues in jms

    I am making messenger using jms Can anyone tell me **if createQueue() or createTemporaryQueue() should be used for queue creation. **if createTemporaryQueue() is used,i think offline messages can't be sent **i am unable to create the queue,plz tell e

  • Ipad software won't update

    I have just tried to update my ipad software from version 4.3.3 (very old & not been updated in yonks!) to the latest version but after 2 hours spent waiting whilst it downloaded the latest software it failed to update my ipad. There was no error mes