Getting year, month and date

I am getting the current year, month and date as follows:
public void setDate(Date date) {
String strDate = "";
//year
Calendar cal = Calendar.getInstance();
cal.setTime(date);
strDate += cal.get(Calendar.YEAR);
//month
strDate += cal.get(Calendar.MONTH) + 1;
//date
strDate += cal.get(Calendar.DATE);
this.date = strDate;
}This gives me the date in teh format yyyymd.
i.e for Mar 5 2007, it returns 200735
How can it retrieve it in yyyymmdd format?
i.e. Mar 5 2007 must be 20070305

use the function:
private String getTwoNumberFormat(int i){
     if (i<10)
          return "0"+i;
     else
          return ""+i;
}and then call
//month
strDate += getTwoNumberFormat(cal.get(Calendar.MONTH)+1);or use SimpleDateFormat :)

Similar Messages

  • How to get date difference in terms of years,months and also days

    Tool : Eclipse
    Framework : JSF & Springs
    JRE : jdk1.5.0_06
    Iam using oracle 10G DB as back end.I have two date fields in a table.
    1)premium_paying_start_date
    2)premium_paying_end_date
    Iam getting these two dates from the database and storing these values within a entity.Now in the delegate layer,
    i have to get the premium_term i.e, the difference between the two dates(premium_paying_end_date-premium_paying_start_date).
    The difference should show the year,month and no of days difference.
    For example :
    premium_paying_start_date : 14-10-1984
    premium_paying_end_date : 01-03-2008
    Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
    So please give me the solution for this.

    Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
    So please give me the solution for this.How did you determine what the difference should be?
    ~

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

  • 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

  • FM to get the number of days in Year,month and days by giving number of day

    Hi ALL,
    This is quit differnt.
    I need to give input the 'start date' and the 'number of days' and get the total days from the start date in year,month and day format.
    for example.
    start date :01.01.2009
    number of days as 32
    then i should get
    years:0
    months :1
    days :1
    Pleas help me out.

    hi Anusha,
    first u pass the date and the days to the following fm you will get the result date....
    data:date type sy-datum,
          r_date(10) type c.
    date = sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
       DAYS              = '32'
       MONTHS            = '0'
       START_DATE        = date
    IMPORTING
       RESULT_DATE       = r_date
    write:/ r_date.
    then you need to pass the result date and the date to the following fm to get the required output...
    CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
        EXPORTING
          date1                   = r_date
          date2                   = date
        IMPORTING
          years                   = v_years
         months                 = v_months
        days                     = v_days
        EXCEPTIONS
          invalid_dates_specified = 1
          OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    here u will get the difference in days,  months and year...
    i hope u wil get help from this...
    regards
    Ashu  Singh

  • Date separate year, month and day

    Hello everyone and thanks in advance, I'm new to this and the truth is not doing this.
    Well, I have a PDF with several pages which I designed and has been asking me in a complete date in the format dd / mm / yy and subsequent pages he asks me the same date of birth but in 3 separate fields, day , month and year. I want you when you enter the date the first copy and separate day month and year in others. I tried this but I get
    var array_datesol = datesol.split("/")
    var year = parseInt(array_datesol[2]);
    var month = parseInt(array_datesoll[1]);
    var day = parseInt(array_datesol[0]);
    this.getField('yearsol').value = year;
    this.getField('monthsol').value = month;
    this.getField('daysol').value = day;
    where is the initial field datesol date and year, month and day where they have to be separately
    thanks in advance

    Are you getting any errors in the JavaScript debugging console?
    You are using the syntax for the 'Custom JavaScript calculation' and this syntax can not be used in the 'simplified field notation. Also you can not use any JavaScript properties, objects, functions, control statments.
    When run in the console, I find you have a misspelling of the variable name 'datesol'. I also do not see where you are initializing the value for 'datesol'.
    var datesol = event.valueAsString;  // get value of this field
    var array_datesol = datesol.split("/") ; // make into an array
    this.getField('yearsol').value =array_datesol[2];  // get element year
    this.getField('monthsol').value = array_datesol[1];  // get month element - fixed variable name
    this.getField('daysol').value = array_datesol[0]; // get date element
    I would use one of the following so the other fields are only updated when a date has been entered and the leading zeros are displayed:
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.value != '') {
    // get parts of date and print with leading zeros
    var datesol = event.value;  // get value of this field
    var array_datesol = datesol.split('/') ; // make into an array
    this.getField('yearsol').value = util.printf('%,304.0f', array_datesol[2]);  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', array_datesol[1]);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', array_datesol[0]); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if (event.value != '') {
    // get date parts and print with leading zeros
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printf('%,302.0f',oDatesol.getFullYear());  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', oDatesol.getMonth() + 1);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', oDatesol.getDate()); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.vaue != '') {
    // get parts of date and format
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printd('yyyy', oDatesol); // get element year
    this.getField('monthsol').value = util.printd('mm', oDatesol); // get month element - fixed variable name
    this.getField('daysol').value = util.printd('dd', oDatesol); // get date element
    If you are going to fill other field, you will need to use the '.valueAsStriing' property or '.toString()'  method to retain the leading zeros.

  • Convert two dates difference to number of years, months and days

    Post Author: gigimonu
    CA Forum: Formula
    I wanted to write a formula (if there is a function I can use) that can convert a date difference to total number of years, months and days example
    adate = 10/22/2006
    ?xdate = current date - adate (answer should be 1 years, 0 months and 0 days)
    Please help
    Thanks

    Post Author: V361
    CA Forum: Formula
    &#91;Years, Months, Days&#93;
    DATEVAR FROMDATE := DATE(2000,01,01); // FROM DATE
    DATEVAR TODATE := CURRENTDATE; // TO DATE
    NUMBERVAR YEARS;
    NUMBERVAR MONTHS;
    NUMBERVAR DAYS;
    STRINGVAR DIFF;
    DATEVAR TEMP;
    IF TODATE < FROMDATE THEN
    (TEMP := TODATE;
    TODATE := FROMDATE;
    FROMDATE := TEMP);
    YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
    IF YEARS > 2 THEN
    (YEARS := YEARS - 2;
    TEMP := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
    ELSE
    (YEARS := 0;
    TEMP := FROMDATE);
    WHILE TRUE DO
    (TEMP := DATE(DATEADD('M',1,TEMP));
    IF TEMP > TODATE THEN
    EXIT WHILE;
    MONTHS := MONTHS + 1);
    DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
    IF MONTHS > 12 THEN
    (YEARS := YEARS + INT(MONTHS/12);
    MONTHS := MONTHS MOD 12);
    DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
    IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
    IIF(DAYS>0 ,TRIM(TOTEXT(DAYS,0)) & " DAYS" ,"0 DAYS");

  • Using SQL stored procedures How to get the list of .rar files from e:\Tempbackup directories from the different remote desktop windows server and delete the .rar files which contains the current month and date

    Concept:
    Every month i need to find the list of .rar files from the
    E:/TempBackup directory from the different environments (remote desktop servers) and i need to delete the current month
    .rar files alone from the respective (E:/TempBackup) directory. below is example files structure inside the
    E:/TempBackup.
    example:
    zDROP_2014_08_31_Backups.rar
    zDROP_2014_09_31_Backups.rar
    zDROP_2014_10_31_Backups.rar
    from the above list i need to delete the zDROP_2014_08_31_Backups.rar(current month) file alone and also logs should be capture for this deletion.
    key words for this are zDROP and Current month and date.
    i need a stored procedure for this concept. could you please help on this.

    Hello,
    You can schedule an operating system task (Control Panel -> Schedule task) to either call a batch file or a PowerShell script.
    Please read the following resources for examples:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/61373719-fffb-4d94-bdbe-7d8ed8620b44/delete-filesfolders-on-remote-servers-using-powershell?forum=winserverpowershell
    http://www.networknet.nl/apps/wp/archives/943
    http://jeffwouters.nl/index.php/2011/10/powershell-script-to-delete-files-older-that-a-week/
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How to get current month and last month dynamically??

    how to get current month and last month dynamically
    like
    month = getCurrentMonth();
    lastmonth = getcurrentMonth() -1;
    please help
    thanks

    hi :-)
    /* depracated but can be still useful */
    java.util.Date dtCurrent = new java.util.Date();
    int month = dtCurrent.getMonth();
    int lastmonth = dtCurrent.getMonth() - 1;
    System.out.println("* " + month);
    System.out.println("* " + lastmonth);
    /* better to use this one */
    Calendar cal = new GregorianCalendar();     
    int imonth = cal.get(Calendar.MONTH);
    int ilastmonth = cal.get(Calendar.MONTH) - 1;
    System.out.println("*** " + imonth);
    System.out.println("*** " + ilastmonth);
    regards,

  • Getting Last Month End date

    Dear Experts,
    I want the following result. I have a date parameter. I want to
    get the last / end date of the previous month
    for any given date which the user inputs.
    For ex:
    If user puts the date 15.06.2008
    then i want to get the previous month end date i.e. 31.05.2008.
    The reason being i am creating a program for updating Opening and Closing Stocks of every month in a ZTABLE. The user will put the date in the parameter and system will bring the closing stock of previous month and then calculate for the current month.
    I hope i am not complicating matters too much....
    Basic funda is to arrive at the end date of the previous month for any date which the user puts.
    Please help me... it is mission critical..
    Thanks & Regards,
    Jitesh M Nair

    hi,
    use this to get last month end date.
    ex:
    data: d2 like sy-datum.
    d2 = sy-datum.
    d2+6(2) = '01'.
    d2 = d2 - 1. "prev mnth last date
    write:/ d2.

  • How can we get Dynamic columns and data with RTF Templates in BI Publisher

    How can we get Dynamic columns and data with RTf Templates.
    My requirement is :
    create table xxinv_item_pei_taginfo(item_id number,
    Organization_id number,
    item varchar2(4000),
    record_type varchar2(4000),
    record_value CLOB,
    State varchar2(4000));
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'USES','fever','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'HOW TO USE','one tablet daily','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'SIDE EFFECTS','XYZ','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'DRUG INTERACTION','ABC','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'OVERDOSE','Go and see doctor','TX');
    insert into xxinv_item_pei_taginfo values( 493991 ,224, '1265-D30', 'NOTES','Take after meal','TX');
    select * from xxinv_item_pei_taginfo;
    Item id Org Id Item Record_type Record_value State
    493991     224     1265-D30     USES     fever     TX
    493991     224     1265-D30     HOW TO USE     one tablet daily     TX
    493991     224     1265-D30     SIDE EFFECTS     XYZ     TX
    493991     224     1265-D30     DRUG INTERACTION     ABC     TX
    493991     224     1265-D30     OVERDOSE      Go and see doctor     TX
    493991     224     1265-D30     NOTES     Take after meal     TX
    Above is my data
    I have to fetch the record_type from a lookup where I can have any of the record type, sometime USES, HOW TO USE, SIDE EFFECTS and sometimes some other set of record types
    In my report I have to get these record typpes as field name dynamically whichever is available in that lookup and record values against them.
    its a BI Publisher report.
    please suggest

    if you have data in db then you can create xml with needed structure
    and so you can create bip report
    do you have errors or .... ?

  • How do i get my songs and data from my old mac onto my pc so that i can copy it onto my new ipod touch

    how do i get my songs and data from my old mac onto my pc so that i can copy it onto my new ipod touch

    jrswish wrote:
    When I plugged in my new one it cleared all my song and apps out of my current itunes.
    Are you sure of that?  Check in the Library.  Click on the Apps icon to see all apps.  Similarly click on the Music icon to see the songs.

  • Seeing the month and date in the finder bar?

    In the 'finder bar(?)' I have the day of the week and the time. Is there anyway to have the month and date there too? Instead of having to click on it and seeing it below?
    Thanks, Jordan

    You can do this via the International preference panel.
    Click on the Customize button next to the "Dates" section.
    Select and copy the entire date there.
    Then click on the "Customize" button next to the "Times" section. Make sure the "show" menu is set to medium. Click to the right of the Time so the insertion point is next to the current time, put a separater character such as "|" then past the date into the field.
    Then close the window. That's it.

  • How to get current time and date??

    How to get current time and date from my PC time and date to the java application??
    i use java.util.* package but got error, that is:
    - java.util.* and java.sql.* class are match
    - abstract class cannot be instantiated
    so what can i do, pls guide...thanks...

    There is a method in the System class that will return the current system time. You could also instantiate a Date, Time, Timestamp, or Calendar object, all of which get created with the system time by default.
    Don't import *. Import the specific classes you need.
    Next time, post the actual text of the exceptions/compile errors. If you make people guess, most just won't bother.

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

Maybe you are looking for

  • N73 software update problem- Be ware

    After updating my N73 to ver,3.070 , Nothing seems to work. delay proplem , cant access my calnder , cant open my text messages.I tried many times to re install in vain. How can I go back to the older software ? Help

  • How can i get session object based on session id?

    I have tried searching in forum but i can't find any solution that i can get session object based on session id and i also would like to know how to check whether the session is still active? My company currently using weblogic 5.1. I really hope tha

  • When attempting to create a system image on an external hard drive, I get an I/O error ox8078002A.

    I'm using a HP Pavilion dv7 notebook PC and a Seagate 3TB USB 3.0 external drive.  OS is Windows7 64-bit.  Microsoft support suggests running chkdsk /R on the Seagate drive and I'm currently doing that (takes a long time).  Another  post suggested tr

  • Problems with variables

    I'm receiving an error from a copied variable in the user exit. Everytime I run the query on the web I get the error message below. Everything is exactly the same from the original logic/variable except the name is YYCP2 and the original is YYCP. The

  • IPod will not turn on. Only displays red cross or apple

    Help! I've been charging it for day's so it's not the battery. I tried following the online instructions to reset but it will not even connect to the computer!