r/programminghelp • • Dec 09 '23

Java Get Dates from CSV

Have a bunch of invoices from work. They’re all saved as CSV. Creating a Java program that reads through the csv and saves it in excel workbook. The goal is a different workbook for each year. Looking for help/insight on a method/code that would help me find year from the csv data, and from that save it in the proper workbook.

I know the date format is mm/dd/yyyy

I tried using if sc.next.length = 10 (10 is the length of the date) but had no luck there.

1 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/ConstructedNewt MOD Dec 11 '23

There is no real universal way. It’s a very generic problem. If you have a text and don’t know where the date is located you can look for patterns with e.g. regex. But it sounds like you have a serialized format (csv) in which data is saved with structure, meaning you know where the data is located always, and only need to parse it. The LocalDate type has some simple parsers built in, or you can formulate your own pattern. The line 68 mention make it sound like you don’t really have csv (columnar) but something else, am I misunderstanding you?