excelcsvdatetimetype-conversiongnucash

How do I easily convert a CSV with a strange date format to a specified format?


This is more a data related question than programming, but I wasn't sure where else to post it. If it better fits elsewhere modders are free to move it.

I'm trying to import a bank exported CSV into GNUcash, but GNUcash only takes specific date formats such as YYYY-MM-DD (1999-05-16), whereas my bank only exports as YYYYMMDD (19990516).

I'm not sure what the easiest / most convenient way is to convert the file for use. Writing a script and/or using complex regexes for it seems excessive but might be necessary?

I tried loading it into LibreOffice Calc and MS Excel but couldn't find any conversion options; formatting the cells with a custom YYYYMMDD format broke the output. I was hoping there was an easier way to solve this. If there isn't I might just end up writing that script and putting it online somewhere.


Solution

  • You could open your CSV with Notepad2, tick regular expression search and replace.

    If the date is written between double quotes and commas :

    ,"([12][90][901]\d)([01]\d)([0123]\d)",
    

    with

    ,"\1-\2-\3",
    

    For anything more complex, Excel macros or Ruby could help you.