• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

POI reads date format in excel as datetime

 
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using POI 3.9 to read Excel file in my application. Though I had the issue of reading dates as doubles that was hushed with the help of DataFormatter class method.

However when using formatCellValue() the dates stored in excel are returned as date with time information regardless if it was a Date or DateTime value (when exported from MySQL).

So how would I read both formats separately? Here is the relevant part of the code

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the connection between "data in an Excel spreadsheet" and "data exported from MySQL"?
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry if the details are blurry. I am required to insert date values into the my table and along with it is also a column timestamp.

In my excel both date and timestamp exists and are shown correctly on checking the cell. But when I read it into my Java app, I want the date cell from excel as 'yyyy-MM-dd' and timestamp cell as 'yyyy-MM-dd HH:mm:ss' . Now it is parsed in the Date form.

How I would differentiate between these two formats while using POI?

My use of the word 'datetime' in the above post might be the cause of confusion.
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are trying to make a distinction which does not exist. Consider this statement from the POI documentation for the Cell interface which I happened to stumble across while researching your post:

Note - There is actually no 'DATE' cell type in Excel. In many cases (when entering date values), Excel automatically adjusts the cell style to some date format, creating the illusion that the cell data type is now something besides CELL_TYPE_NUMERIC. POI does not attempt to replicate this behaviour.

 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic