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

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

  • 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

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

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

  • 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

  • How can i get the month and year of the current  open Periode?

    At the beginning of each month the booking period for the new month was not open,but i need to book material automatically with the last day of the old month. The booking period will change at the first working day between 13 and 17 a clock. when the booking period was changed i have to book with the current date.
    How can i do this ??
    Regards
    Ralf

    Hi Ralf,
    here's a complete example:
    DATA: last LIKE sy-datum, "ultimo of last month
          gjahr LIKE t001b-frye1,
          buper LIKE t001b-frpe1.
    last = sy-datum - sy-datum+6(2) .
    PERFORM check_period.
    IF sy-subrc <> 0.
      ADD 1 TO last . "-> next month
      PERFORM check_period.
      IF sy-subrc <> 0.
        MESSAGE a001(00) WITH 'no open fi period'.
      ENDIF.
    ENDIF.
    *formatting for germany
    CONCATENATE last+6(2) last+4(2) last(4) INTO bbkpf-budat.
    WRITE: / bbkpf-budat.
    FORM check_period.
      MOVE last(4) TO gjahr.
      MOVE last+4(2) TO buper.
      CALL FUNCTION 'FI_PERIOD_CHECK'
           EXPORTING
                i_bukrs          = bbkpf-bukrs
                i_gjahr          = gjahr
                i_koart          = '+'
                i_monat          = buper
           EXCEPTIONS
                error_period     = 1
                error_period_acc = 2
                OTHERS           = 3.
    ENDFORM.                    " check_period
    regards <a href="https://www.sdn.sap.com:443/irj/servlet/prt/porta
    l/prtroot/com.sap.sdn.businesscard.SDNBusinessCard?u=i
    Wo3ssHlIihvCrADIEGqaw%3D%3D">Andreas</a>
    Message was edited by: Andreas Mann

  • 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

  • Need to combine month and year to get date YYYY-MM-DD format

    Month and year are table fields and they will have values like
    Month in format = mm  example 01
    year in format = YYYY example 2010
    Now i need to concatenate month and year to derive date .
    Expected result Result :2010-01-01
    Example :Month =01
    Year =2010
    Mudassar

    The principle of any tiered architecture is that display formatting is done in a presentation layer. This is not just SQL and Client/Server programming; it is the foundation of all modern programming. Not knowing this is like a doctor who does not know
    about germs or a chemist who does not know about atoms. 
    This is reviewed in the first 1-2 weeks of any database class. Why are you violating it?? 
    Next, you do not even know that column are not fields! 
    T-SQL now has a DATE data type, which defaults to the ISO-8601 display format (yyyy-mm-dd). Are you using it? If you had been polite we would see your DDL and know. 
    --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

  • Display month and year in dropdown list on selection screen

    Hi
      Can anyone tell me how to display months and year in a dropdown list on a selection screen?
      also please tell me how to get the first and the last dates upon selecting the month and year on the dropdown list.
    Month: January Year:2007 . 
    After selecting the required month and year, the first date and last date i.e '01.01.2007 - 31.01.2007' should be displayed on the right side.
    Reward Points assured..
    thanks,
    Chetan

    Hi..,
    <b>
    Just copy, paste and execute this program !!</b>
    type-pools: vrm.
    parameters : p_month(2) type n as listbox visible length 10,
    p_year(4) type n as listbox visible length 10.
    DATA : W_DATE type d, w_ldate type d.
    initialization.
    perform user_drop_down_list_fordt.
    perform user_drop_down_list_foryr.
    start-of-selection.
    concatenate p_year p_month '01' into w_date.
    call function 'BKK_GET_MONTH_LASTDAY'
      exporting
        i_date        = w_date
    IMPORTING
       E_DATE        = w_ldate
    write /: w_date,w_ldate.
    build user_drop_down_list
    form user_drop_down_list_fordt.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    data: t_months type t247 occurs 0 with header line.
    clear list. refresh list.
    name = 'P_MONTH'.
    select * into  table t_months
    from t247 where spras eq 'EN'.
    sort t_months ascending by mnr.
    loop at t_months.
    clear value.
    value-key = t_months-mnr.
    value-text = t_months-ltx.
    append value to list.
    endloop.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    for year...
    form user_drop_down_list_foryr.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    clear list. refresh list.
    name = 'P_YEAR'.
    do 9999 times.
    clear value.
    value-key = sy-index.
    append value to list.
    enddo.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    <b>
    Hope this solves ur problem..</b>
    regards,
    sai ramesh

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

  • Sorting grouped values by month and year within chart

    Hello
    I have a really tough problem which I can't seam to figure out.
    I have a table called SOLAR_RETURN which has 4 columns:
    - ID
    - USER_ID
    - DATUM
    - RETURN
    On a page I have 3 links, one for showing the information from the database by day, month or year.
    The hidden field :P25_DATE_FILTER is being set through the URL when clicking one of the 3 links.
    I have a linechart with the following sql statement which pulls the correct data according to the value of :P25_DATE_FORMAT:
    select null link, to_char("SOLAR_RETURN"."DATUM", :P25_DATE_FILTER) as label, max("SOLAR_RETURN"."RETURN") as value from "SOLAR_RETURN"
    WHERE "SOLAR_RETURN"."USER_ID" = :USER_ID
    AND to_char(DATUM, :P25_DATE_FILTER) = decode(:P25_DATE_FILTER,'YYYY',to_char(DATUM, 'YYYY'),'MM-YYYY',to_char(DATUM, 'MM-YYYY'),'DD-MM-YYYY',to_char(DATUM, 'DD-MM-YYYY'))
    GROUP BY to_char(DATUM, :P25_DATE_FILTER)
    Everything is working great, only the sorting is messed up. I need to sort it so that when :P25_DATE_FORMAT is set to DD-MM-YYYY it will be sorted by year desc, month desc, day desc. If the value would be MM-YYYY it would need to sort by year desc, month desc.
    I have tried the following without succes:
    ORDER BY to_char(DATUM, :P25_DATE_FILTER) ASC
    --> This doesnt cut it since it sorts like this: (for example)
    01-2010
    02-2010
    11-2009
    12-2009
    Vice versa for DESC
    Is there any way that I can sort the grouped values by day, month and year seperately?
    Thanks in advance!
    Marc

    Hi,
    What is data type for column DATUM ?
    If it is date did you try ORDER BY DATUM DESC ?
    Br,Jari

  • Anyone help me ...I am writing to get Date, Month and Year...I got errors

    Could some body help me:
    I am try to get Date, Month and Year
    I got stuck, Anyone help me this:
    public class DateMonth
    public static void main(String[] args)
    toDay = new toDay("February 21, 2002");
    dayofWeek = today.getDay();
    System.out.println("Current month is " + toDay.getMonth());
    System.out.println("Current day is " + getDate());
    System.out.println("Current year is " + toDay.getYear());
    toDay.setDate(toDay.getDate()+60)
    System.out.println("Sixty days from now is ");
    System.out.println(toDay);
    }

    Try something like this:
    import java.util.*;
    public class DateMonth {
         public static void main(String[] args) {
              // Note: 0 = January
              Calendar calendar = new GregorianCalendar();
              System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
              System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
              System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
              System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
              System.out.println("DATE: " + calendar.get(Calendar.DATE));
              System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
              System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
              System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
              // 60 days from now
              calendar.add(calendar.DATE, 60);
              System.out.println("\nSixty days from now");
              System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
              System.out.println("DATE: " + calendar.get(Calendar.DATE));
              System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    }Remember that January is 0!
    Take a look at the GregorianCalendar class:
    http://java.sun.com/j2se/1.3/docs/api/java/util/GregorianCalendar.html
    Hope this helps!
    DesQuite

  • Getting all dates of a particular month and year

    I want to get list of all dates of a particular month and year .
    How to get using Calendar List?

    Create a Calendar object. Set it's month and year. Then call getActualMaximum(Calendar.DAY_OF_MONTH); on the Calendar object. That will tell you how many days are in the month of that year.

Maybe you are looking for

  • Access denied when deploying task details to non-soa server

    Jdev 11g. I am deploying task details to non-soa server following this guideline: http://aseng-wiki.us.oracle.com/asengwiki/display/ATG/Deploying+Human+Task+Detail+Page+on+Remote+NonSOA+Server+In+Drop+7 The error is: Access to internal workflow conte

  • How ro run unix script freom pl/sql - dbms_scheduler 11.2.0.3

    Hi, Using 11.2.0.3 and have a unix script which works fine. Want to run this unix script every time a piece of pl/sql runs have put below in but doesn't actually run it. How can we achieve this? Many Thanks idea is that file we create locqally on ser

  • How do I fix a js3250.dll system error

    Just today I attempted to download and run the latest version of Kompozer on my desktop, but it wouldn't function properly due to a js3250.dll missing error, which to my understanding is a component of Firefox. How do I resolve this issue? I've tried

  • The New Guide. GARBAGE!

    Should i expect a pair of binoculars in the mail from verizon to ty to read the new guide? Seriously. Who thought that it was a great idea to make the logos and the things that appear on it so small that everytime that you try to read what is on it y

  • New Photos App - Can't Import Video from Digital Camera

    Hi, everyone.  I just "upgraded" to the new Photos app, but I'm finding that I can no longer import video from my Panasonic Lumix DMC-LX5.  With iPhoto, this was never a problem.  All of the old videos I imported from this camera are there after migr