09-28-2024, 07:09 AM | #1 |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
Search and Replace with Regex
I have a column (#startdates) with comma separated text, like tags, with a date in the following format: 2024.09.21
I want to insert this date into a date column (#dateread) with the format 'dd MMM yyyy'. Could someone please help me? Edit: Or does it work easier with action chain and a template? Last edited by Wiggo; 09-28-2024 at 07:13 AM. |
09-28-2024, 12:39 PM | #2 | |
Grand Sorcerer
Posts: 12,014
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If it is the first or only value, then I suggest you use a search & replace using "Template" as the source. The template would be Code:
program: format_date(sublist(#startdates, 0, 1, ','), 'dd MMM yyyy') Code:
program: format_date(sublist(#startdates, -1, 0, ','), 'dd MMM yyyy') The search & replace dialog contents:
As always, be careful when using search & replace. Try it on a few books before running it on your entire library. Backing up your library is a good plan. |
|
Advert | |
|
09-28-2024, 01:08 PM | #3 |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
Thank you so much, chaley!
Unfortunately I get this error Code:
calibre, version 7.19.0 FEHLER: Fehlgeschlagen: Unknown string format: S/R-Vorlagenfehler Formatter: Failed to scan program. Invalid input '#startdates, 0, 1, ','), 'dd MMM yyyy')' near the end of the program Traceback (most recent call last): File "calibre\gui2\dialogs\metadata_bulk.py", line 198, in do_it File "calibre\gui2\dialogs\metadata_bulk.py", line 535, in do_all File "calibre\db\cache.py", line 85, in call_func_with_lock File "calibre\db\cache.py", line 1636, in set_field File "calibre\db\write.py", line 568, in set_books File "calibre\db\write.py", line 568, in <dictcomp> File "calibre\db\write.py", line 73, in adapt_datetime File "calibre\utils\date.py", line 114, in parse_date File "dateutil\parser\_parser.py", line 1368, in parse File "dateutil\parser\_parser.py", line 643, in parse dateutil.parser._parser.ParserError: Unknown string format: S/R-Vorlagenfehler Formatter: Failed to scan program. Invalid input '#startdates, 0, 1, ','), 'dd MMM yyyy')' near the end of the program |
09-28-2024, 01:13 PM | #4 |
Grand Sorcerer
Posts: 12,014
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Sorry, I forgot the '$' when I replaced my test lookup name with your lookup name. It should be
Code:
program: format_date(sublist($#startdates, 0, 1, ','), 'dd MMM yyyy') |
09-28-2024, 01:37 PM | #5 | |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
Quote:
But I get this error message for 'Dezember' - language thing? Code:
calibre, version 7.19.0 FEHLER: Fehlgeschlagen: Unknown string format: 30 Dez 2023 Traceback (most recent call last): File "calibre\gui2\dialogs\metadata_bulk.py", line 198, in do_it File "calibre\gui2\dialogs\metadata_bulk.py", line 535, in do_all File "calibre\db\cache.py", line 85, in call_func_with_lock File "calibre\db\cache.py", line 1636, in set_field File "calibre\db\write.py", line 568, in set_books File "calibre\db\write.py", line 568, in <dictcomp> File "calibre\db\write.py", line 73, in adapt_datetime File "calibre\utils\date.py", line 114, in parse_date File "dateutil\parser\_parser.py", line 1368, in parse File "dateutil\parser\_parser.py", line 643, in parse dateutil.parser._parser.ParserError: Unknown string format: 30 Dez 2023 Last edited by Wiggo; 09-28-2024 at 01:45 PM. |
|
Advert | |
|
09-28-2024, 01:49 PM | #6 | |
Grand Sorcerer
Posts: 12,014
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The right way to fix this is to change (if necessary) the definition of the #dateread column to have the format you want, 'dd MMM yyyy'. Once you do that then you don't need the format_date() at all. Simply copy the date from #startdates to #dateread as it is. Calibre will convert it to a date then display it using the format you specify in the column definition. In this case the template becomes Code:
program: sublist($#startdates, 0, 1, ',') |
|
09-28-2024, 02:01 PM | #7 | |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
Quote:
|
|
09-29-2024, 12:50 AM | #8 |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
One more question please, chaley.
The timestamp has the time 00:00:00 CEST. Can this be changed? When daylight saving time is changed again, all dates have a timeshift of -1 day, which admittedly annoys me a bit. |
09-29-2024, 05:38 AM | #9 | |
Grand Sorcerer
Posts: 12,014
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: date_arithmetic(sublist($#startdates, 0, 1, ','), '12h') |
|
09-29-2024, 07:51 AM | #10 |
Leftutti
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
|
Thx, chaley!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to replace text with Search and Replace with regex on Calibre | darrnih | ePub | 2 | 04-02-2024 02:10 AM |
Regex in search problems (NOT Search&Replace; the search bar) | lairdb | Calibre | 3 | 03-15-2017 07:10 PM |
Regex: Search and Replace | Thomas_AR | Calibre | 2 | 03-31-2016 06:23 PM |
regex search/replace - how to? | Alt68er | Sigil | 1 | 03-11-2014 08:53 PM |
need regex help search and replace | schuster | Calibre | 4 | 01-10-2011 09:00 AM |