How to access a specific entry on a csv file based on todays date

Hello,
I am trying to write a program that reports back a specific set of numbers based on todays date. i would like for it to look for todays date and report back the set of four digits next to it.
I would appreciate any help
Thanks
Dan

|9/20/2022|3894|
|9/21/2022|4067|
|9/22/2022|4239|
|9/23/2022|4412|
|9/24/2022|4585|
|9/25/2022|4758|
|9/26/2022|4930|
|9/27/2022|5103|
|9/28/2022|5276|
|9/29/2022|5449|
|9/30/2022|5621|
|10/1/2022|5794|
|10/2/2022|5967|
|10/3/2022|6140|
|10/4/2022|6312|
|10/5/2022|6485|
|10/6/2022|6658|
|10/7/2022|6831|
|10/8/2022|7003|
|10/9/2022|7176|
|10/10/2022|7349|
|10/11/2022|7522|
|10/12/2022|7694|

Apart from reading in the file itself - line by line…
Read up on strtok() to separate the fields by the pipe | delimiter.

Look it up where? Where is this list of dates and associated numbers stored?

Are they in order? Do you know already how many they are?

a7

A possibility.

Thank you for the prompt response, i will look up strtok() tonight.

I am trying to create a standalone arduino with display that looks at the current date and reports back the number in the cell next to it. Currently i have a spreadsheet with the information, this is for a password that we use on our equipment at work that changes daily. The spreadsheet works fine, i would just like make it a little more fun to display the number.
I can extract the spreadsheet into a csv file. or i can manually type into the c code. The dates are in order Decending by date. and currently i would like to have enough to finish out the year so about 100 dates with corresponding code of the day next to each
Thank you to everyone replying

Thank you

If you are free to select the format of the file then using a binary rather than textual representation will make it easier to read.
If you have one entry per day You could have 4 bytes for the start date and then a series of 2 bytes for the code.

Reading the first 4 bytes will let you know to know when the file starts and calculating the number of days elapsed since that date gives you an offset to jump to the right position in the file (multiplying by the 2 bytes for the code).
So everything is static and you do just one read for the start date, a seek to go to the right position and a read for the 2 bytes for the code. No need to parse and compare which will take a long time if the date is far down the file

Sorry, not getting it.

Are the date/number pairs on an SD card the Arduino reads? The "csv file"?

Or listed in the program as data? Like you take the csv file and massage it to make it into an initialiser for some data structure in the program?

a7

Currently i have an excel file that i can save as a csv file, i can either type in manually in to the program or if possible access the csv file.

Then you read a line into a buffer, extract the date, compare with target date and if it matches then extract the code. If not read next line and rinse and repeat

So the arduino will have a clock/calendar? Otherwise, how does it know today's date?

After having fought with this for several months, please examine you csv file with a dumb display program and ensure it is what you think it is. The current excel program from Microsoft adds a bunch of stuff you don't need.

I plan on having an rtc hooked up to it to keep track of the day, basically if date = 9/20/22 then print 3894.

1 Like

Thank you Paul, i will double check it.

yes, and it could either compare date to a csv file or check the data built in to the code.
what is the best and easiest way to do this?

If you store the data as you did say a char array for the date and a char array for thé code you need 11 bytes for the date and 5 for the code (with trailing null end marker), so 16 bytes per entry.
You have 100 entries so you need 1600 bytes.
Depending on the arduino you use and what the rest of the code needs to do, that might be tough to get that in SRAM of a UNO or Nano for example but it will fit in flash memory though.
Trade off is that you need to modify and recompile the code and upload again when the 100 dates have been used.

Using an SD card is more generic and you basically have no limits and could store easily decades worth of secret codes in one go or just update the file when needed + restart and no code modification is needed for the foreseeable future.

You need to decide how you get the current day’s date (an RTC ? NTP request ?) as well

Presuming you really need the date in every line. I hate storing information that the code can regenerate. Storing the date sequence is equivalent to creating a 2D array just so you can store the row index in the first element of each row. The only reason to store the dates would be if you had a discontinuity in the array, where you skipped days for some reason.
I'd organize it as "starting date" as a separate element, then just the numeric password codes for each date. Any subsequent date is calculable as an index. That reduces the storage to 12 bytes for the date (which could actually be a long unsigned int), and an array of 2*N bytes, where N is the number of days you want to store.
C

That’s basically what I was suggesting in post 8

Based on my working with a similar file from a spreadsheet, you do not have any fixed length data, so you cannot compute your way to a specific position in the csv file. Serial reading will be the only way.

You could preprocess the csv file and create a file with fixed length fields and store that new file for your searching.