Page 1 of 2 12 LastLast
Results 1 to 20 of 25
Like Tree1Likes

Thread: Read Date from Excel and change its Format

  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Read Date from Excel and change its Format

    Hello,

    i have excel file and i want to reat some column and insert it in Db, any way i want to read Column with date
    PHP Code:
    Date
    ========
    14.12.2010
    15.12.2010
    16.12.2010
    17.12.2010
    18.12.2010
    19.12.2010
    20.12.2010
    21.12.2010
    22.12.2010
    Java Code:
    public class Date_DB {
        
        private String name;
        private Date dateOfCommission;
       //Setters und Getters
    Calss To read from Excel
    Java Code:
    Date_DB pp = new Date_DB();
    pp.setDateOfCommission(row.getCell(12).getDateCellValue());  ///date
    set.add(pp);
    But it reads the Date as the flowing:
    XML Code:
    Tue Dec 14 00:00:00 CET 2010
    Wed Dec 15 00:00:00 CET 2010
    Thu Dec 16 00:00:00 CET 2010
    Fri Dec 17 00:00:00 CET 2010
    Sat Dec 18 00:00:00 CET 2010
    Sun Dec 19 00:00:00 CET 2010
    Mon Dec 20 00:00:00 CET 2010
    Tue Dec 21 00:00:00 CET 2010
    Wed Dec 22 00:00:00 CET 2010
    Now what i wish is to reformat this Date to be exactly like in the Excel file (have Format ""dd.MM.yyyy" ) and store them ad a Date in the Set

    I read a lot about Calender Format, but i didn't find any thing really helpful

    Any Help?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Read Date from Excel and change its Format

    A Date is a Date. You just see different String representations of it. If you want to modify the displayed String, have a look at SimpleDateFormat.
    gimbal2 likes this.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    The good old 'data' VS 'the presentation of data'. They're absolutely not the same thing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    Ok very well, i know that, but now i need really to change its format to something like "dd.MM.yyyy", and i know that i should use SimpleDateFormat, but some how i don'nt know how to use it right during reding the Date cells from the excel file

    The Problem that SimpleDateFormat return Type String and i need just to deal with Date
    Java Code:
    SimpleDateFormat  sdf = new SimpleDateFormat("dd.MM.yyyy");
    pp.setDateOfCommission(sdf.format(row.getCell(12).getDateCellValue())); // error: The method setDateOfCommission(Date) in the type Date_DB is not applicable for the arguments (String)
    or something like that
    Java Code:
    SimpleDateFormat  sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date date = sdf.parse(pp.setDateOfCommission(row.getCell(12).getDateCellValue())); //error: The method parse(String) in the type DateFormat is not applicable for the arguments (void)
    so how to deal with it?

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    apparently you don't understand that because in stead of formatting the date in the place where it is PRESENTED, you are now formatting the date in the place where you CREATE it. But that is not going to work because your Date_DB objects wants a Date object, not a String.

    In your first post you have that long list of printed dates. Where did that list come from? What piece of code printed those dates in the wrong format. That is where you need to be applying your SimpleDateFormat.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    This snippet gernerate the worng format
    Java Code:
    Date_DB pp = new Date_DB();
    pp.setDateOfCommission(row.getCell(12).getDateCellValue());  ///date
    System.out.println("date: " + pp.getDateOfCommission());
    set.add(pp);
    and i applied the SimpleDateFormat exactly in the same snippet, otherwise if you mean to use it with Print statement like this
    Java Code:
    System.out.println("date: " + sdf.format(row.getCell(12).getDateCellValue()));
    it will print the correct date format, but i don't wish to print it, i want to store it after change its format in HashSet not just display it

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Read Date from Excel and change its Format

    Again, a Date doesn't have a format. Only it's String representation has one.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    Ok whatever the Format of Date, how ti achieve my question?

  9. #9
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    I'm giving up.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    it is really very difficult !!!

  11. #11
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    That's what you get when you just try stuff in stead of a) getting a proper education and b) don't take the time to think about it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    believe me i posted the question just after looking for the solution in the API and internet, and after that i posted this thread

    All what i wish is a little help or a any tip

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    You've gotten it, multiple times in very plain English.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Read Date from Excel and change its Format

    Ok, one last try.
    "14.12.2010" and "Tue Dec 14 00:00:00 CET 2010" are the same Date in time on your wall calendar and your desk calendar. Just your wall calendar has green day numbers and your desk calendar red day numbers. Just a different diplay of the same thing.
    Your original code works fine:
    Java Code:
    Date_DB pp = new Date_DB();
    pp.setDateOfCommission(row.getCell(12).getDateCellValue());  ///date
    set.add(pp);
    The only difference is that as soon as you look at the dates in the set, you see a display which might differ.
    You're currently complaining, that I gave you $1 although I owed you 100 cents.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  15. #15
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    Ok, the problem that i wish to insert this calender in DB, and it should display as simple format like "dd.MM.yyyy", but if i insert it immediately without changing its Format it will be not pretty look in the DB

  16. #16
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Read Date from Excel and change its Format

    OK, now I give up too.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  17. #17
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: Read Date from Excel and change its Format

    I wanted any hints or ideas not general talk about the colors, i don't know what is the relative between your explanation with my problem, of course it is obvious that "14.12.2010" and "Tue Dec 14 00:00:00 CET 2010" are the same Date, but i want to store it as a certain format in the Hashset before insert it in the DB, any way sorry to waste your time and thanks for the help
    Last edited by vector_ever; 08-22-2013 at 04:58 PM.

  18. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Read Date from Excel and change its Format

    Have a glass of water, a meal if it's mealtime and curl up with a big cup of coffee and this:
    https://forums.oracle.com/thread/2044092

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  19. #19
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,110
    Rep Power
    4

    Default Re: Read Date from Excel and change its Format

    I actually remember that thread. I remember doing a few facepalms when reading it. I must have grown as a person, since in this thread I just started crying.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  20. #20
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Read Date from Excel and change its Format

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 04-17-2012, 08:25 AM
  2. julian date to full date format
    By judy318 in forum New To Java
    Replies: 7
    Last Post: 11-02-2009, 12:17 PM
  3. How to change the format of date?
    By jboy in forum New To Java
    Replies: 1
    Last Post: 09-09-2009, 01:22 PM
  4. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 05:16 PM
  5. Replies: 1
    Last Post: 10-10-2008, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •