Skip invalid dates

47 views
Skip to first unread message

Damon Abdiel

unread,
Oct 12, 2023, 2:14:29 PM10/12/23
to hle...@googlegroups.com
Hello

I have this rules for Import CSV:

```

skip 1
separator ,

fields Type,Status,Date,Payee,Category/Account,Amount,Note,Memo,Tags,Number,Security,Shares,Price/Share,Commission

description %Payee
comment %Memo
currency BRL
amount %Amount
account2 Expenses:%4
date-format %-d/%-m/%y

```

I try to migrate my data from Banktivity to hledger

I export my data from Banktivity and some transactions have splits, see:

```
Type,Status,Date,Payee,Category/Account,Amount,Note,Memo,Tags,Number,Security,Shares,Price/Share,Commission
Withdrawal,*,03/10/23,Booking.com,Laura,"-6.833,65",,,,,,"","",""
Withdrawal,*,02/10/23,MOBILEPAG TIT 2650434570,(split),"150,00",MOBILEPAG TIT 2650434570,,,20231002005,,"","",""
,"","","",Itau,"6.833,02",,,
,"","","",Pai 9144 Personnalite,"-6.364,39",,,
,"","","",Web 0967 Personnalite,"-269,91",,,
,"","","",Eve 7025 Personnalite,"-875,08",,,
,"","","",Temp Personnalite,"826,36",,,
```

On line 4 I get an error:

```
hledger: Error: error: could not parse "" as a date using date format "%-d/%-m/%y"
CSV record: "","","","","Itau","6.833,02","","",""
the date rule is: %3
the date-format is: %-d/%-m/%y
you may need to change your date rule, change your date-format rule, or change your skip rule
for m/d/y or d/m/y dates, use date-format %-m/%-d/%Y or date-format %-d/%-m/%Y
```

I tried skipping this invalid date, I put this in my new rules files:

```
...


if [%2 = '']
skip

...

```


But she skipped all the lines :(

Someone let me know where my error is here.



Damon Abdiel



-----
Sent from macOS Big Sur



Simon Michael

unread,
Oct 13, 2023, 6:25:44 AM10/13/23
to hledger
Hi Damon,

> if [%2 = '']
>  skip 

This is valid syntax but it's not doing what you think. Check the manual about `if` and regular expressions. 

How about something like this:

if %Date ^$
 skip




--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hledger/43FC9549-AC72-45C9-AEF1-9B81C5B6CF59%40abdiel.app.br.

Reply all
Reply to author
Forward
0 new messages